androidandroid-sliding

How to change android slidingdrawer handle button position


In default handle button in android SlidingDrawer in the centre of the drawer. Is it possible to change that position to left or right..? If it possible how can I do that, android:gravity="left" is not work in the button.


Solution

  • Put your handle in a RelativeLayout, and set android:layout_alignParentRight="true" on the handle.

    For example like this:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
        <SlidingDrawer android:id="@+id/drawer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:handle="@+id/handle" 
            android:content="@+id/content">
    
            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:id="@+id/handle">
                <ImageView android:src="@drawable/icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true" />
            </RelativeLayout>
    
            <LinearLayout 
                android:gravity="center" 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#aaaa00" android:id="@+id/content">
                <ImageView android:src="@drawable/icon"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center">
                </ImageView>
            </LinearLayout>
    
        </SlidingDrawer>
    
    </FrameLayout>