gpt4 book ai didi

android - 如何在右侧显示 SlidingPaneLayout?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:08 24 4
gpt4 key购买 nike

你好我是 android 的初学者,在我的应用程序中我必须在右侧显示 SlidingPaneLayout 但使用我下面的代码它来自左侧。

请帮帮我。

如何让它在右侧?

第二,我的要求是我的 SlidingPaneLayout 必须重叠在操作栏上,但使用我下面的 xml 代码 SlidingPaneLayout 显示如下图

请建议我如何解决这两个问题

工具栏布局:-

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp"
>

</android.support.v7.widget.Toolbar>

Activity 滑动:-

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/SlidingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="right">

<ListView
android:id="@+id/MenuList"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#101010"
android:orientation="vertical" >

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/android_robot" />
</LinearLayout>

</android.support.v4.widget.SlidingPaneLayout>

主要布局:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/tool_bar"
layout="@layout/toolbar_layout">
</include>

<include
android:id="@+id/SlidingPanel"
layout="@layout/activity_sliding">
</include>

</LinearLayout>

enter image description here

最佳答案

在您的 list 中,将以下属性添加到开头 <application>标签。

android:supportsRtl="true"

然后把这个属性加到开头SlidingPaneLayout在布局中标记。

android:layoutDirection="rtl"

最后,移动 tool_bar <include>元素进入主要内容LinearLayoutSlidingPaneLayout 内, 并调整 ImageView的高度和体重。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#101010"
android:orientation="vertical">

<include
android:id="@+id/tool_bar"
layout="@layout/toolbar_layout">
</include>

<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/android_robot" />

</LinearLayout>

请注意 child View SlidingPaneLayout 的小号将继承 rtl layoutDirection .这可能会导致 child 出现问题 View s 如果它们的布局行为受方向影响。例如,水平方向的 LinearLayout将从右边开始布置它的 child 。这很容易通过设置 android:layoutDirection="ltr" 来解决。在受影响的View

另请注意,此示例对布局中的方向进行了硬编码。如果您需要在整个应用程序范围内同时支持 LTR 和 RTL 布局,您需要以编程方式执行此操作,并考虑到设备的默认方向。

关于android - 如何在右侧显示 SlidingPaneLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36660629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com