Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show SlidingPaneLayout at right side?

Hi I am a beginner for android and in my app I have to show SlidingPaneLayout at the right side but using my below code it's coming from left side.

Please help me.

How can I make it be at right side?

And second my requirement is my SlidingPaneLayout must be overlapped on Action bar but using my below xml code SlidingPaneLayout showing like my below image

please suggest me how can resolve this two problem

toolbar_layout:-

<?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_sliding:-

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

main_layout:-

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

like image 753
Krish Avatar asked Apr 16 '16 05:04

Krish


1 Answers

In your manifest, add the following attribute to the opening <application> tag.

android:supportsRtl="true"

Then add this attribute to the opening SlidingPaneLayout tag in your layout.

android:layoutDirection="rtl"

And finally, move the tool_bar <include> element into the main content LinearLayout within the SlidingPaneLayout, and adjust the ImageView's height and weight.

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

Please note that the child Views of the SlidingPaneLayout will inherit the rtl layoutDirection. This may cause problems in child Views if their layout behavior is affected by the direction. For example, a horizontally-oriented LinearLayout will lay out its children starting from the right. This is easily remedied by setting android:layoutDirection="ltr" on the affected Views.

Also note that this example hard codes the direction in the layout. If you need to support both LTR and RTL layouts application-wide, you'll need to do this programmatically, accounting for the device's default direction.

like image 52
Mike M. Avatar answered Nov 10 '22 02:11

Mike M.