Search code examples
androidandroid-layoutslidingdrawer

Sliding Drawer Android


I have used android:rotation="180" to make the sliding drawer horizontal to appear on left of screen. It works fine. But, the contents appears upside down in it because of the rotation. I tried to rotate the content layout also, but it gets rotated only after the sliding drawer is completely open. Please check my code attached with this.

MainActivity.java

public class MainActivity extends Activity {

ArrayAdapter<String> myAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView LV = (ListView) findViewById(R.id.listView1);

    String [] List =  {"item 1","item 2","item 3","item 4"};
    myAdapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.textView1, List);
    LV.setAdapter(myAdapter);

    }

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >

<SlidingDrawer
    android:id="@+id/slidingDrawer1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:content="@+id/listView1"
    android:handle="@+id/handle"
    android:orientation="horizontal"
    android:rotation="180" >

<Button
    android:id="@+id/handle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Handle" />

 <ListView
     android:id="@+id/listView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:rotation="180"
     tools:listitem="@layout/list_item" >
  </ListView>

</SlidingDrawer>

list_item.xml

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="10dp"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

Solution

  • I've implemented a complete replacement for the SlidingDrawer component and it works from any side/direction. see http://www.github.com/kedzie/DraggableDrawers for details.

    Now available from Maven Central ( maven-android-plugin ):

    <dependency>
      <groupid>com.github.kedzie.draggabledrawers</groupId>
      <artifactId>library</artifactId>
      <version>1.0.0</version>
      <type>apklib</type>
    </dependency>