Tuesday, January 29, 2013

Android Sliding Drawer TOP to DOWN

we can make sliding drawer in Android 3.0 and above easily with rotation.

for this purpose make a project with the name SlidingDrawer and copy the following code to your's
MainActivity.java


package com.jitesh.slidingdrawer;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

the main.xml should have following layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background" >

    <SlidingDrawer
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/slidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="250dip"
        android:content="@+id/content"
        android:gravity="center_horizontal"
        android:handle="@+id/handle"
        android:orientation="vertical"
        android:rotation="180" >

        <LinearLayout
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:rotation="180"
                android:src="@drawable/arrow" />
        </LinearLayout>

        <ImageView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FF0000"
            android:rotation="180"
            android:src="@drawable/love" />
    </SlidingDrawer>

</RelativeLayout>



use the following resources in your's res/drawable folder

the output is as following



Please download the code here SlidingDrawer

6 comments: