user3449772
user3449772

Reputation: 757

Custom drawer navigation layout (xml)

I've a problem to create a custom navigation drawer for Android. I've an xml layout but I think that is bad... The menu items are not aligned...why?

Image

and this is the layout:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/spinnerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="0dp">

        <Spinner
            android:id="@+id/drawerSpinner"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/headerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="20dp">

        <TextView
            android:id="@+id/drawerTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:layout_marginBottom="1dp"
            android:layout_marginTop="1dp"
            android:background="#DADADC" ></View>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/itemLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:orientation="vertical"
        android:layout_marginTop="0dp"
        android:background="?android:attr/activatedBackgroundIndicator">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:minHeight="50dp"
            android:layout_gravity="center_vertical">

            <ImageView
                android:id="@+id/drawer_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <TextView
                android:id="@+id/drawer_itemName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"/>
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginBottom="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#DADADC"
            ></View>

    </LinearLayout>

</RelativeLayout>

Thank you!

Upvotes: 1

Views: 428

Answers (1)

joao2fast4u
joao2fast4u

Reputation: 6892

Just add android:gravity="center" on your itemLayout LinearLayout and your items will be centered.

Upvotes: 1

Related Questions