1

NavigationDrawer在我的应用程序中使用主菜单。我的一些片段使用SlidingPaneLayout.

目前,我展示了NavigationDrawer右边和SlidingPaneLayout左边的,总是有点明显。

但我想让NavigationDrawer左侧和SlidingPaneLayout右侧的 (就像在环聊中一样)总是有点可见。

问题:

我知道如何将其NavigationDrawr移至另一侧,但我不知道如何(如果可能)将其SlidingPaneLayout移至右侧?所以它从右边滑入...

我的解决方案

<android.support.v4.widget.SlidingPaneLayout
    android:id="@+id/sliding_pane_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/fragment_main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:layout_marginRight="0dp"
        android:orientation="vertical" >

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/card_toast_container" />

        <FrameLayout
            android:id="@+id/fragment_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!-- marginLeft: set it to width - 150 in your code!!! -->

    <FrameLayout
        android:id="@+id/fragment_slider"
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:layout_marginLeft="0dp" />
</android.support.v4.widget.SlidingPaneLayout>

并使用一些包装方法,例如以下,以获得更容易和更易读的代码:

public boolean isSliderMenuShown()
{
    return !mSlidingLayout.isOpen();
}

public static void openSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
    slidingLayout.closePane();
}

public static void closeSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
    slidingLayout.openPane();
}
4

4 回答 4

1

将此设置为在导航抽屉内查看:

android:layout_gravity="left"

您可以尝试在开始时将其保持打开状态:

SlidingPaneLayout sp = (SlidingPaneLayout) findViewById(R.id.spl);
sp.openPane();

还要将主要内容保留在左侧,将菜单保留在右侧

于 2013-12-11T09:09:11.533 回答
1

经过我的研究和测试,android.support.v4.widget.SlidingPaneLayout无法从右向左滑动。唯一的效果是从左向右滑动。不管android:layout_gravity=start left end还是right

于 2015-04-10T09:03:38.477 回答
1

您可以通过为您的滑动面板布局添加布局方向来实现这一点

layout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
        layout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

在此之前,请确保您已 android:supportsRtl="true"为清单文件添加了一个属性。

于 2016-09-21T13:29:10.907 回答
0

第1步

为了在您的应用程序中支持 RTL,您首先需要将 android:supportsRtl="true" 添加到清单文件中的元素中。

第2步

在 SlidingPaneLayout 中添加 RTL 支持

安卓:layoutDirection="rtl"

Step-3 在 SlidingPaneLayout 的子视图中添加 LTR 支持

安卓:layoutDirection="ltr"

    <SlidingPane
        android:id="@+id/slidingPanelLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutDirection="rtl">

        <include
            layout="@layout/left_drawer"
            android:layout_width="250dp"
            android:layout_height="match_parent"
            android:layoutDirection="ltr" />

        <include
            layout="@layout/view_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layoutDirection="ltr"
          />
    </SlidingPane>

注意:在 left_drawer.xml、view_container.xml 中添加 LTR 支持

于 2020-12-08T05:53:57.650 回答