2016-01-19 49 views
4

我在ToolBar中放入了LinearLayout1,然後在LinearLayout1中放入了另外5個LinearLayout。每個孩子LinearLayout都有一個ImageView。這裏我的問題是LinearLayout1不匹配父寬度。我在圖像中顯示(紅色圓圈)。黑色是我給ToolBar的背景。ToolBar中的LinearLayout與父項不匹配

<android.support.v7.widget.Toolbar 
    android:id="@+id/featured_bottomToolbar" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_gravity="bottom" 
    android:background="#000000" 
    android:layout_alignParentBottom="true"> 


    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/menu_black_featured" 
       android:id="@+id/imageView" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/menu_grey_justin2" 
       android:id="@+id/imageView2" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/menu_grey_designers" 
       android:id="@+id/imageView3" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/menu_grey_categories" 
       android:id="@+id/imageView4" /> 
     </LinearLayout> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="0dp" 
      android:layout_weight="2" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="@drawable/meny_grey_more2" 
       android:id="@+id/imageView5" /> 
     </LinearLayout> 

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

我得到的輸出。

enter image description here

+1

後的代碼,以便我們可以幫助你。 –

+0

您是否使用工具欄手動創建tabhost? –

+0

我已發佈。請通過它並幫助。 –

回答

34

將以下屬性添加到您的Toolbar元素中。

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 

contentInsetStart的默認值是16dp。您需要將其設置爲0

0

嘗試調用:

mToolbar = (Toolbar) findViewById(R.id.featured_bottomToolbar); 
mToolbar.setContentInsetsAbsolute(0, 0); 

Toolbar實例。

1
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/featured_bottomToolbar" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_gravity="bottom" 
     android:background="#000000" 
     app:contentInsetLeft="0dp" 
     app:contentInsetStart="0dp" 
     android:layout_alignParentBottom="true"> 


     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/menu_black_featured" 
        android:id="@+id/imageView" /> 
      </LinearLayout> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/menu_grey_justin2" 
        android:id="@+id/imageView2" /> 
      </LinearLayout> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/menu_grey_designers" 
        android:id="@+id/imageView3" /> 
      </LinearLayout> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/menu_grey_categories" 
        android:id="@+id/imageView4" /> 
      </LinearLayout> 

      <LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:src="@drawable/meny_grey_more2" 
        android:id="@+id/imageView5" /> 
      </LinearLayout> 

     </LinearLayout> 
    </android.support.v7.widget.Toolbar> 
</RelativeLayout> 
+0

我已經加入://外佈局 的xmlns:應用= 「http://schemas.android.com/apk/res-auto」 //在工具欄 應用程式:contentInsetLeft = 「0dp」 應用: contentInsetStart =「0dp」 –

-1

你也需要做:

getSupportActionBar().setDisplayHomeAsUpEnabled(false); 
+0

如果使用自己的工具欄,則無效並崩潰。 – SoftDesigner

相關問題