SlidingDrawer in Android UI Control

SlidingDrawer

SlidingDrawer is a control which hides content (controls and text level) out of the screen and allows the user to drag a handle to bring the content on the screen.

SlidingDrawer can be used vertically or horizontally. A special Widget composed of two children views:

1) the handle: this is used to be drag by the user and content attached to the handle.

2) the content:the content layout is attached to the handle and drag on to the screen when the user pulls the handle.

sliding drawer should be used as an overlay inside layouts, this means that sliding drawer should only be used inside of a frame layout or a relative layout. the size of the sliding drawer defines how much space the content will occupy one slide out.

inside a xml layout sliding drawer must define the ID of the handle and the content layout.

Attributes of sliding drawer:-

a) android:allowSingleTab : it is used to set weather the drawer can be open/close by a single tab on a handle.

b) android:animateOnClick : this attribute sets weather the drawer should be open/close with an animation effect when the     user click on the handle.

c) android:bottomOffset : this sets the extra off sets for the handle at the bottom of the SlidingDrawer.

d) android:content : this attribute act as an identifier for the child that represents the drawers content.

e) android:handle : this attribute act as an identifier for the child that represents the drawers handle.

f) android:orientation : this sets the orientation of the sliding drawer.

g) android:topOffset : this sets the extra off sets for the handle at the top of the SlidingDrawer.

 

.xml file: 

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/LinearLayout01″
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”@drawable/androidpeople”>
<SlidingDrawer android:id=”@+id/SlidingDrawer”
android:layout_alignParentBottom=”true”
android:layout_width=”fill_parent”
android:layout_height=”250dip”
android:handle=”@+id/slideHandleButton”
android:content=”@+id/contentLayout”
android:padding=”10dip”
android:orientation=”vertical”>

<Button android:id=”@+id/slideHandleButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/closearrow” />

<LinearLayout android:id=”@+id/contentLayout”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”#c1cdcd”
android:gravity=”center|top”
android:orientation=”vertical”
android:padding=”10dip” >

<Button android:id=”@+id/Button01″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/download” />

<Button android:id=”@+id/Button02″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/download1″
android:layout_marginTop=”15dp”/>

<Button android:id=”@+id/Button03″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/images”
android:layout_marginTop=”15dp”/>

</LinearLayout>

</SlidingDrawer>

</RelativeLayout>

 

Java file: 

package com.CoreProgrammers.drawer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.Toast;

public class slidingDrawerExample extends Activity
{

Button slideHandleButton;
SlidingDrawer slidingDrawer;
Button Button01;
Button Button02;
Button Button03;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
Button01= (Button) findViewById(R.id.Button01);
Button02= (Button) findViewById(R.id.Button02);
Button03= (Button) findViewById(R.id.Button03);

slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener()
{
@Override
public void onDrawerOpened()
{
slideHandleButton.setBackgroundResource(R.drawable.openarrow);
}
});

slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener()
{

@Override
public void onDrawerClosed()
{
slideHandleButton.setBackgroundResource(R.drawable.closearrow);
}

});

Button01.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{

Toast toast = Toast.makeText(slidingDrawerExample.this, “Facebook!!”, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.LEFT, 0 , 0);
toast.show();
}
});

Button02.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{
Toast toast = Toast.makeText(slidingDrawerExample.this, “Whatsapp!!”, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.LEFT, 0 , 0);
toast.show();
}
});

Button03.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{
Toast toast = Toast.makeText(slidingDrawerExample.this, “linkedin!!”, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.LEFT, 0 , 0);
toast.show();
}
});

}

}

Skip to toolbar