2014-10-31 55 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