2014-10-31 31 views
4

我想根據這個草圖來實現內通過新程序兼容性庫提供了新的工具欄插件自定義佈局不正確的行爲的意見

enter image description here

所以我嘗試添加新在工具欄內部佈局組件,並將其重力屬性設置爲bottom | center_horizo​​ntal。但是看起來這個屬性完全沒有關係,我的子佈局總是位於工具欄的垂直中心和漢堡圖標的左側。

enter image description here

我的XML佈局看起來是這樣的:

<LinearLayout 
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="match_parent" 
android:orientation="vertical"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="115dp" 
    android:background="?attr/colorPrimary" 
    app:titleTextAppearance="@style/title"> 

    <RelativeLayout 
     android:layout_width="176dp" 
     android:layout_height="59dp" 
     android:background="?attr/colorPrimaryDark" 
     android:gravity="bottom|center_horizontal"> 

    </RelativeLayout> 

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


<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/container_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <ListView 
     android:id="@+id/drawer_menu" 
     android:layout_width="264dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@android:color/white" 
     android:choiceMode="singleChoice" 
     android:divider="?android:colorBackground" 
     android:dividerHeight="1dp"/> 

</android.support.v4.widget.DrawerLayout> 

任何想法如何實現的內部工具欄子視圖正確對準?

+2

是到Lorem存有替代) – 2014-10-31 18:41:13

回答

9

編輯:android:gravity定義如何對齊內容的視圖(文本對齊,子視圖,等等),而不是在它的父視圖的視圖的對準。

變化

android:gravity="bottom|center_horizontal" 

android:layout_gravity="bottom|center_horizontal" 
+0

哦,謝謝。對我感到羞恥 - 選擇了錯誤的屬性 – 2014-10-31 18:44:23