繁体   English   中英

将FrameLayout移到左侧(包含一个SlidingDrawer Button手柄)

[英]Move FrameLayout to the left (containing a SlidingDrawer Button handle)

我有一个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>

这可能已经晚了,但是mi8可以帮助其他人,因为我也曾经非常需要它

我没有在手柄按钮周围使用任何布局

我刚刚添加

android:padding ='<显示尺寸的3/4 >>'

在您的slideDrawer 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>

尝试添加

android:orientation="horizontal"

在您的slideDrawer xml中

您还可以看到此链接,

如何使Android SlidingDrawer从左侧滑出?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM