Change android SlidingDrawer handle button position

Sliding drawer left to right, right to left, top to bottom, bottom to top opening example with source code.

Handle button is used to handle sliding drawer events like opening sliding drawer, closing slider drawer and app developer can change the whole sliding drawer positing as they required in project. So here is the complete step by step tutorial for Change android SlidingDrawer handle button position.

android-project-download-code-button

Note: I am using a sample image as sliding drawer opening layout so download this image from below and put into res->drawable-hdpi folder.

drawable hdpi folder

Image to download:

background_image

How to Change android SlidingDrawer handle button position.

What i am doing in this project : I am creating 4 buttons on MainActivity left to right, right to left, top to bottom, bottom to top and after click on button it will open new android activity containing button name sliding drawer.
Code for MainActivity.java file.

 package com.slidingdrawerhandlebutton_android_examples.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class MainActivity extends Activity {

 Button Bottom2Top,Top2Bottom,Left2Right,Right2Left;
 Intent intent;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 Bottom2Top = (Button)findViewById(R.id.button3);
 Top2Bottom = (Button)findViewById(R.id.button4);
 Left2Right = (Button)findViewById(R.id.button1);
 Right2Left = (Button)findViewById(R.id.button2);
 
 Bottom2Top.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 intent = new Intent(MainActivity.this, BottomTOTopActivity.class);
 startActivity(intent);
 
 }
 });
 
 Top2Bottom.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 intent = new Intent(MainActivity.this, TopTOBottomActivity.class);
 startActivity(intent);
 
 }
 });
 
 Left2Right.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 intent = new Intent(MainActivity.this, LeftTORightActivity.class);
 startActivity(intent);
 
 }
 });
 
 Right2Left.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 intent = new Intent(MainActivity.this, RightTOLeftActivity.class);
 startActivity(intent);
 
 }
 });
 }
}

Code for activity_main.xml layout file.

<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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.slidingdrawerhandlebutton_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="170dp"
 android:text="OPEN LEFT TO RIGHT SLIDING DRAWER" />

 <Button
 android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button1"
 android:layout_centerHorizontal="true"
 android:text="OPEN RIGHT TO LEFT SIDE SLIDING PANEL" />

 <Button
 android:id="@+id/button3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBottom="@+id/button1"
 android:layout_centerHorizontal="true"
 android:layout_marginBottom="60dp"
 android:text="OPEN BOTTOM TO TOP SLIDING DRAWER" />

 <Button
 android:id="@+id/button4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button2"
 android:layout_centerHorizontal="true"
 android:text="OPEN TOP TO BOTTOM SLIDING DRAWER" />
 
</RelativeLayout>

 

Code for BottomTOTopActivity.java file.

package com.slidingdrawerhandlebutton_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class BottomTOTopActivity extends Activity {

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

Code for activity_bottom_totop.xml layout file.

<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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.slidingdrawerhandlebutton_android_examples.com.BottomTOTopActivity" >

 <SlidingDrawer
 android:id="@+id/slidingDrawer1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 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="Handle" />

 <LinearLayout
 android:id="@+id/content"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 
 <ImageView 
 android:id="@+id/imgview1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/background_image"/>
 
 
 </LinearLayout>
 </SlidingDrawer>

</RelativeLayout>

 

Code for LeftTORightActivity.java file.

package com.slidingdrawerhandlebutton_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class LeftTORightActivity extends Activity {

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

Code for activity_left_toright.xml layout file.

<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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.slidingdrawerhandlebutton_android_examples.com.LeftTORightActivity" >

 <SlidingDrawer
 android:id="@+id/slidingDrawer1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:content="@+id/content"
 android:handle="@+id/handle"
 android:rotation="180"
 android:orientation="horizontal" >

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

 <LinearLayout
 android:id="@+id/content"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 
 <ImageView 
 android:id="@+id/imgview1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/background_image"/>
 
 </LinearLayout>
 </SlidingDrawer>

</RelativeLayout>

 

Code for RightTOLeftActivity.java file.

package com.slidingdrawerhandlebutton_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class RightTOLeftActivity extends Activity {

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

Code for activity_right_toleft.xml layout file.

<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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.slidingdrawerhandlebutton_android_examples.com.RightTOLeftActivity" >

 <SlidingDrawer
 android:id="@+id/slidingDrawer1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:content="@+id/content"
 android:handle="@+id/handle"
 android:orientation="horizontal" >

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

 <LinearLayout
 android:id="@+id/content"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 
 <ImageView 
 android:id="@+id/imgview1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/background_image"/>
 
 </LinearLayout>
 </SlidingDrawer>

</RelativeLayout>

 

Code for TopTOBottomActivity.java file.

package com.slidingdrawerhandlebutton_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class TopTOBottomActivity extends Activity {

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

Code for activity_top_tobottom.xml layout file.

<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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.slidingdrawerhandlebutton_android_examples.com.TopTOBottomActivity" >

 <SlidingDrawer
 android:id="@+id/slidingDrawer1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:content="@+id/content"
 android:handle="@+id/handle"
 android:orientation="vertical"
 android:rotation="180" >

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

 <LinearLayout
 android:id="@+id/content"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 
 <ImageView 
 android:id="@+id/imgview1"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/background_image"/>
 
 </LinearLayout>
 </SlidingDrawer>

</RelativeLayout>

 

Code for AndroidManifest.xml file.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.slidingdrawerhandlebutton_android_examples.com"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 <activity
 android:name=".BottomTOTopActivity"
 android:label="@string/title_activity_bottom_totop" >
 </activity>
 <activity
 android:name=".LeftTORightActivity"
 android:label="@string/title_activity_left_toright" >
 </activity>
 <activity
 android:name=".RightTOLeftActivity"
 android:label="@string/title_activity_right_toleft" >
 </activity>
 <activity
 android:name=".TopTOBottomActivity"
 android:label="@string/title_activity_top_tobottom" >
 </activity>
 </application>

</manifest>

Screenshots:

Change android SlidingDrawer handle button position

Click Here to download Change android SlidingDrawer handle button position project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *