Use Of Sliding Drawer
As we are know that mobile has limited resources in terms of memory,screen etc. so as we also had limited one screen at a time to manage so many items. For that we have to make complex layout to manage the screen item as well as display information to user. For that we manage screen two way.
1)Use LayoutInflater
2)Use Menu
and Another way is Use Sliding Drawer View.
Sliding Drawer Contain One Button,Linear Layout.
You can put any view in this Liner Layout.
Layout xml File In- res/layout/activity_main.xml
activity_main.xml
<RelativeLayout 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:background="@drawable/background" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world" />
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#F8F88B" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world" />
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#F8F88B" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Layout xml File In- res/layout/row.xml
row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="25dp"
android:textStyle="bold" >
</TextView>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="25dp"
android:textStyle="bold" >
</TextView>
Java File In -src/com.example.sliding
MainActivity.java
package com.example.slidingview;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class MainActivity extends Activity {
Button handle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.listView1);
handle = (Button) findViewById(R.id.handle);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
R.layout.row);
arrayAdapter.add("Hardik Patel");
arrayAdapter.add("Umang Patel");
arrayAdapter.add("Jignesh Desai");
arrayAdapter.add("Urvish Patel");
arrayAdapter.add("Archit Patel");
arrayAdapter.add("Amit Patel");
arrayAdapter.add("Dashrath Chavada");
arrayAdapter.add("Rushit Joshi");
arrayAdapter.add("Jimit Shah");
arrayAdapter.add("Dhaval Patel");
arrayAdapter.add("Chintan Patel");
lv.setAdapter(arrayAdapter);
SlidingDrawer sd = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
sd.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
handle.setText("Open");
}
});
sd.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
handle.setText("Close");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class MainActivity extends Activity {
Button handle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.listView1);
handle = (Button) findViewById(R.id.handle);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
R.layout.row);
arrayAdapter.add("Hardik Patel");
arrayAdapter.add("Umang Patel");
arrayAdapter.add("Jignesh Desai");
arrayAdapter.add("Urvish Patel");
arrayAdapter.add("Archit Patel");
arrayAdapter.add("Amit Patel");
arrayAdapter.add("Dashrath Chavada");
arrayAdapter.add("Rushit Joshi");
arrayAdapter.add("Jimit Shah");
arrayAdapter.add("Dhaval Patel");
arrayAdapter.add("Chintan Patel");
lv.setAdapter(arrayAdapter);
SlidingDrawer sd = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
sd.setOnDrawerCloseListener(new OnDrawerCloseListener() {
public void onDrawerClosed() {
handle.setText("Open");
}
});
sd.setOnDrawerOpenListener(new OnDrawerOpenListener() {
public void onDrawerOpened() {
handle.setText("Close");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
No comments:
Post a Comment
Must Comment