I am trying to implement custom layout inside new Toolbar widget provided by new AppCompat library according to this sketch
So I am trying to add new Layout component inside Toolbar and set it's gravity attributes to bottom|center_horizontal. But it seems like this attribute completely doesn't matter and my child layout always positioned on the vertical center of Toolbar and to left of hamburger icon.
My XML-layout looks like this:
<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>
Any ideas how to achieve correct alignment of child views inside Toolbar?
EDIT: android:gravity
defines how to align the inner content of the view (text alignment, child views, etc.), not the alignment of the view in its parent view.
change
android:gravity="bottom|center_horizontal"
to
android:layout_gravity="bottom|center_horizontal"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With