我有一个Button,它是SlidingDrawer的句柄。我有另一个按钮,我希望可以在与SlidingDrawer按钮句柄相同的行上访问。对于LinearLayout或RelativeLayout,这似乎不可能,但我可以通过FrameLayout使它工作。
我的问题是:句柄按钮只会在屏幕中央显示。我希望每个按钮位于屏幕的两侧(按钮手柄位于右侧,另一个按钮位于左侧)。如何将此FrameLayout包装的按钮移动到屏幕右侧?一切都包含在RelativeLayout中,但我还没能实现这个按钮移动。
相关的Android XML布局代码(再次包含在RelativeLayout中):
<Button android:id="@+id/EditListActivityButton"
android:text="@string/mappage_edititems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/addItemSlidingDrawerHandle"
android:layout_above="@+id/item">
</Button>
<SlidingDrawer android:id="@+id/addItemSlidingDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="@+id/addItemSlidingDrawerHandle"
android:content="@+id/addItemSlidingDrawerContent"
android:layout_above="@+id/item"
android:layout_alignParentRight="true">
<FrameLayout android:id="@id/addItemSlidingDrawerHandle"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/goToEditListButton">
<Button android:id="@+id/addItemSlidingDrawerHandleButton"
android:text="@string/mappage_additem"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</FrameLayout>
<LinearLayout android:id="@id/addItemSlidingDrawerContent"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#96C120">
<!-- sliding drawer content goes here -->
</LinearLayout>
</SlidingDrawer>
答案 0 :(得分:1)
这可能会迟到,但是mi8可以帮助其他人,因为我太需要它了一次
我没有在句柄按钮周围使用任何布局
我刚刚添加了
android:padding ='&lt; 3/4显示尺寸&gt;'
你的slidingDrawer xml 中的
示例(只需粘贴到xml并运行):
<?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="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"/>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingBottom="250dp"
android:src="@drawable/ic_launcher"/>
<LinearLayout
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp"
android:background="#55000000">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
答案 1 :(得分:-1)
尝试添加
android:orientation="horizontal"
你的slidingDrawer xml 中的
您还可以看到此链接,
How to make an Android SlidingDrawer slide out from the left?