首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在右侧显示SlidingPaneLayout?

如何在右侧显示SlidingPaneLayout?
EN

Stack Overflow用户
提问于 2016-04-16 05:48:55
回答 1查看 7.3K关注 0票数 11

嗨,我是安卓的初学者,在我的应用程序中,我必须在右边显示SlidingPaneLayout,但是用我下面的代码,它是从左边来的。

请帮帮我。

我怎么才能让它在右边呢?

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

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

工具栏布局:-

代码语言:javascript
复制
<?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>

活动滑动:-

代码语言:javascript
复制
<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>

主要布局:-

代码语言:javascript
复制
<?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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-16 06:52:30

在清单中,向开头的<application>标记添加以下属性。

代码语言:javascript
复制
android:supportsRtl="true"

然后将此属性添加到布局中的开始SlidingPaneLayout标记中。

代码语言:javascript
复制
android:layoutDirection="rtl"

最后,将tool_bar <include>元素移动到SlidingPaneLayout中的主要内容LinearLayout中,并调整ImageView的高度和权重。

代码语言:javascript
复制
<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>

请注意,View的子SlidingPaneLayout将继承rtl layoutDirection。如果子View的布局行为受到方向的影响,则可能会造成问题。例如,面向水平的LinearLayout将从右开始布局它的子级。这很容易通过在受影响的View上设置View来补救。

还要注意,此示例对布局中的方向进行了硬编码。如果您需要同时支持LTR和RTL布局应用程序,则需要以编程的方式完成这一任务,同时考虑到设备的默认方向。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36660629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档