Android Sliding Drawer is an attractive bone in android for giving a great feel and look to application. for this purpose
Create a project named SlidingDrawerDemo and copy this java code into SlidingDrawerDemo .java.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
android:background="@drawable/bkg1">
<TextView
android:text="SlidingViewer Demo By Jitesh"
android:gravity="center|center_vertical"
android:textColor="#ff0000"
android:textSize="25sp"
android:textStyle="bold|italic"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<SlidingDrawer
android:layout_width="wrap_content"
android:id="@+id/SlidingDrawer"
android:handle="@+id/slideButton"
android:content="@+id/contentLayout"
android:padding="10dip"
android:layout_height="250dip"
android:orientation="vertical">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/slideButton"
android:background="@drawable/openarrow">
</Button>
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/contentLayout"
android:orientation="vertical"
android:gravity="center"
android:padding="10dip"
android:background="@drawable/android"
android:layout_height="wrap_content">
<Button
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/yellow_button"
android:layout_margin="2dp"
android:text="Option1">
</Button>
<Button
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue_button"
android:layout_margin="2dp"
android:text="Option2"></Button>
<Button android:id="@+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/yellow_button"
android:text="Option3">
</Button>
<Button android:id="@+id/Button04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/blue_button"
android:text="Option4">
</Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
the used resource images are as follows
Create a project named SlidingDrawerDemo and copy this java code into SlidingDrawerDemo .java.
package com.jitesh.slidingdrawerdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.Toast;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class SlidingDrawerDemo extends Activity implements OnClickListener {
Button slideButton,b1, b2,b3,b4;
SlidingDrawer slidingDrawer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
slideButton = (Button) findViewById(R.id.slideButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
b1 = (Button) findViewById(R.id.Button01);
b2 = (Button) findViewById(R.id.Button02);
b3 = (Button) findViewById(R.id.Button03);
b4 = (Button) findViewById(R.id.Button04);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
slideButton.setBackgroundResource(R.drawable.closearrow);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
slideButton.setBackgroundResource(R.drawable.openarrow);
}
});
}
public void onClick(View v) {
Button b = (Button)v;
Toast.makeText(SlidingDrawerDemo.this, b.getText() + " Clicked", Toast.LENGTH_SHORT).show();
}
}
correspondingly the android main.xml is represented the following elements
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
android:background="@drawable/bkg1">
<TextView
android:text="SlidingViewer Demo By Jitesh"
android:gravity="center|center_vertical"
android:textColor="#ff0000"
android:textSize="25sp"
android:textStyle="bold|italic"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<SlidingDrawer
android:layout_width="wrap_content"
android:id="@+id/SlidingDrawer"
android:handle="@+id/slideButton"
android:content="@+id/contentLayout"
android:padding="10dip"
android:layout_height="250dip"
android:orientation="vertical">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/slideButton"
android:background="@drawable/openarrow">
</Button>
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/contentLayout"
android:orientation="vertical"
android:gravity="center"
android:padding="10dip"
android:background="@drawable/android"
android:layout_height="wrap_content">
<Button
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/yellow_button"
android:layout_margin="2dp"
android:text="Option1">
</Button>
<Button
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue_button"
android:layout_margin="2dp"
android:text="Option2"></Button>
<Button android:id="@+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/yellow_button"
android:text="Option3">
</Button>
<Button android:id="@+id/Button04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/blue_button"
android:text="Option4">
</Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
the used resource images are as follows
No comments:
Post a Comment