문제

I'm using a NavigationDrawer as main menu in my app. Some of my fragments use the SlidingPaneLayout.

At the moment, I show the NavigationDrawer on the right and the SlidingPaneLayouton the left, always a little bit visible.

But I would like to have the NavigationDrawer on the left side and the SlidingPaneLayout on the right side (like in Hangouts) always a little bit visible.

Question:

I know how to get the NavigationDrawr to the other side, but I can't find out how (if possible) to move the SlidingPaneLayout to the right side? So that it slides in from the right...

my solution

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

and use some wrapping methods like for example following, for easier and more readable code:

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();
}
도움이 되었습니까?

해결책

Set this to view inside navigation drawer:

android:layout_gravity="left"

you can try keeping it open in the start with:

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

Also keep your main content on the left and menu on the right

다른 팁

After my research and test, android.support.v4.widget.SlidingPaneLayout can't swipe out from right to left. The only effect is swiping out from left to right. No matter whether android:layout_gravity= is start left end or right.

You can achieve that by adding the layout direction for you Slidingpanel layout

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

before that make sure you have added a property android:supportsRtl="true" for your manifest file.

Step-1

In order to support RTL in your app, you first need to add android:supportsRtl="true" to the element in your manifest file.

Step-2

Add RTL support in SlidingPaneLayout

android:layoutDirection="rtl"

Step-3 Add LTR support in child views of SlidingPaneLayout

android: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>

Note: add LTR support in both left_drawer.xml, view_container.xml

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top