简体   繁体   English

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

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

I have a Button which is the handle for a SlidingDrawer. 我有一个Button,它是SlidingDrawer的句柄。 I have another button I want to be accessible on the same row as the SlidingDrawer button handle as well. 我还有一个希望与SlidingDrawer按钮手柄在同一行上可访问的按钮。 This does not seem possible with a LinearLayout or a RelativeLayout, but I can get it working via a FrameLayout. 使用LinearLayout或RelativeLayout似乎无法实现,但是我可以通过FrameLayout使其工作。

My issue is this: the handle button will only display itself in the center of the screen. 我的问题是:手柄按钮只会在屏幕中央显示。 I want each button to be on opposite sides of the screen (the button handle to be on the right, and the other button to be on the left). 我希望每个按钮都位于屏幕的相对两侧(按钮手柄位于右侧,另一个按钮位于左侧)。 How can I move this FrameLayout-wrapped Button to the right of the screen? 如何将这个由FrameLayout包装的按钮移动到屏幕右侧? Everything is wrapped in a RelativeLayout, but I have not been able to achieve this button move yet. 一切都包装在RelativeLayout中,但是我还无法实现此按钮移动。

Relevant Android XML layout code (once again, all wrapped in a 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>

This may be late, but mi8 help some others since Me too needed it badly once 这可能已经晚了,但是mi8可以帮助其他人,因为我也曾经非常需要它

I didnt use any layout around my handle button 我没有在手柄按钮周围使用任何布局

I just added 我刚刚添加

android:padding='<3/4 th of ur display size>' android:padding ='<显示尺寸的3/4 >>'

in your slidingDrawer xml 在您的slideDrawer xml中

Example(just paste in a xml and run): 示例(只需粘贴到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>

Try adding 尝试添加

android:orientation="horizontal"

in your slidingDrawer xml 在您的slideDrawer xml中

You can also see this link, 您还可以看到此链接,

How to make an Android SlidingDrawer slide out from the left? 如何使Android SlidingDrawer从左侧滑出?

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

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