2017-06-10 19 views
-1

我在工具栏内添加了一些视图,但显示了一些我想要删除的左侧填充。删除工具栏中的左侧空格android

enter image description here 我想删除这些'删除此空间部分。

这里是我的XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.swornimlab.swornimlab.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      > 
      <include 
       layout="@layout/layout_inside_toolbar" /> 
     </android.support.v7.widget.Toolbar> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main" /> 

</android.support.design.widget.CoordinatorLayout> 

查看,我想里面的工具栏添加:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="?attr/actionBarSize"> 
    <LinearLayout 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     > 
     <TextView 
      android:text="Hello, Asmin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/> 
     <TextView 
      android:text="Welcome Home" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> 
    </LinearLayout> 
    <ImageView 
     android:layout_weight="1" 
     android:src="@drawable/ic_home_vc" 
     android:tint="@android:color/white" 
     android:layout_alignParentRight="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" /> 
</LinearLayout> 
+0

[R u需要汉堡包按钮 – Raj

回答

0
android:layout_gravity="center_vertical" 

这似乎是问题。

也在另一个说明,我建议你使用percentRelativelayout为您的布局分布。使用重量与您的线性布局是非常昂贵的

+0

我改为相对布局,但没有奏效。我认为这是因为导航图标 –

1

从布局中删除android:layout_gravity="center_vertical"

工具栏:

要删除剩余空间添加app:contentInsetStart
要删除右键空间添加app:contentInsetEnd

<android.support.v7.widget.Toolbar 
         android:id="@+id/toolbar" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:background="?attr/colorPrimary" 
         app:popupTheme="@style/AppTheme.PopupOverlay" 
         app:contentInsetEnd="0dp" 
         app:contentInsetStart="0dp"> 

         <include 
          layout="@layout/layout_inside_toolbar" /> 

      </android.support.v7.widget.Toolbar> 

layout_inside_toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="?attr/actionBarSize"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:text="Hello, Asmin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/> 
     <TextView 
      android:text="Welcome Home" 
      android:layout_marginTop="10dp" 
      android:gravity="left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"/> 
    </LinearLayout> 
    <ImageView 
     android:layout_weight="1" 
     android:src="@drawable/ic_home_vc" 
     android:tint="@android:color/white" 
     android:layout_alignParentRight="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" /> 
</LinearLayout> 
+0

我做了你说的,但它不工作 –

+0

也删除android:layout_weight =“1” – Nikunj

+0

我认为这是因为导航菜单图标 –

0

enter image description here试试这个。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_gravity="center_vertical" 
       android:layout_weight="1" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="left" 
        android:text="Hello, Asmin" 
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:gravity="left" 
        android:text="Welcome Home" 
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" /> 
      </LinearLayout> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_centerVertical="true" 
       android:layout_weight="1" 
       android:src="@drawable/ic_home_white_24dp" 
       android:tint="@android:color/white" /> 
     </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_mech_main" />