将 FrameLayout 移至左侧(包含 SlidingDrawer Button 手柄)

发布于 2024-12-17 07:24:29 字数 1734 浏览 0 评论 0原文

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

困倦 2024-12-24 07:24:29

这可能已经晚了,但 mi8 帮助了其他一些人,因为一旦

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

我也非常需要它,我只是添加了

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

在你的 movingDrawer 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>

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>
鹿港小镇 2024-12-24 07:24:29

尝试添加

android:orientation="horizontal"

到slidingDrawer xml中

您还可以看到此链接,

如何让Android SlidingDrawer从左侧滑出?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文