简体   繁体   中英

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

I have a Button which is the handle for a SlidingDrawer. I have another button I want to be accessible on the same row as the SlidingDrawer button handle as well. This does not seem possible with a LinearLayout or a RelativeLayout, but I can get it working via a 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? Everything is wrapped in a RelativeLayout, but I have not been able to achieve this button move yet.

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

I didnt use any layout around my handle button

I just added

android:padding='<3/4 th of ur display size>'

in your slidingDrawer xml

Example(just paste in a xml and run):

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

You can also see this link,

How to make an Android SlidingDrawer slide out from the left?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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