如何改变安卓slidingdrawer手柄按钮位置手柄、按钮、位置、slidingdrawer

2023-09-13 00:42:01 作者:一笑奈何

在Android中SlidingDrawer默认的手柄按钮,在抽屉的中心。是否有可能改变位置向左或向右..?如果可能,我怎么能做到这一点,安卓重力=左未在按钮的工作

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.

推荐答案

把你的手柄在RelativeLayout的,并设置机器人:layout_alignParentRight =真上的手柄

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

例如是这样的:

<?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>