Sliding effect in AndroidSliding effect in Android

In this article, I am going to tell you about sliding effect in android.

Basically sliding is use to save the space of our screen window. Sliding hides content out of the screen and allows the user to drag a handle to bring the content on screen. The size of the Sliding defines how much space the content will occupy once slid out so Sliding should usually use match parent for both its dimensions. Inside an XML layout, Sliding must define the id of the handle and of the content.

Here I will tell you that how can create sliding effect in android application without any use sliding control like as SlidingDrawer control. 

Follow the steps which are given below and you can create a sliding effect in android application.

·         Open Eclipse

·         Select New Android Application Project

·         Enter Application Name as SlideTopToBottom

·         Click Next

·         Click Finish.


After completing my coding and designing the final output will be like this


Sliding effect in Android

Now go to the res/Layout/activity_main.xml and write the following code


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=""





    android:orientation="vertical" >


<!--Transparent is a class which find your actions and slid    -->

<!-- Open Transparent class-->








        android:padding="30px" >






            android:text="Select Country" />


<!-- Add the checkbox for to select the  country name -->







            android:textSize="17dp" />







            android:textSize="17dp" />







            android:textSize="17dp" />






            android:text="South Africa"

            android:textSize="17dp" />

<!-- Close Transparent class-->



<!—ImageView is use for to show the icon for sliding-->






        android:src="@drawable/sliding_Img" />

<!—Sliding_Img is a drawable image  -->








        android:text="OK" />





Now go to the and follow the code



package com.example.slidetoptobottom;


import android.os.Bundle;



import android.text.Layout;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;


public class MainActivity extends Activity {


                                TextView tvCountry;

                int key = 0;



                public void onCreate(Bundle savedInstanceState) {



                                tvCountry = (TextView) findViewById(;


                                final Transparent popup = (Transparent) findViewById(;


//First time visibility should be hide of window




                                final ImageView imgview = (ImageView) findViewById(;

                                imgview.setOnClickListener(new View.OnClickListener() {



                                                public void onClick(View arg0) {

                                                                if (key == 0) {

                                                                                key = 1;

//In clicking then visibility will be show of the popup window. Popup is an object of Transport class.



                                                                } else if (key == 1) {

                                                                                key = 0;










Now create a new class whose name should be

In Transparent class write the following code


package com.example.slidetoptobottom;


import android.content.Context;




import android.util.AttributeSet;

import android.widget.LinearLayout;


public class Transparent extends LinearLayout {

                private Paint innerPaint, borderPaint;


                public Transparent(Context context, AttributeSet as) {

                                super(context, as);




                public Transparent(Context context) {





                private void init() {


// set the color, border, alignment and width.


                                innerPaint = new Paint();

                                innerPaint.setARGB(111, 111, 111, 111);


                                borderPaint = new Paint();

                                borderPaint.setARGB(255, 255, 255, 255);






                public void setInnerPaint(Paint innerPaint) {

                                this.innerPaint = innerPaint;



                public void setBorderPaint(Paint borderPaint) {

                                this.borderPaint = borderPaint;


//This method will be arrange the text in rectangle


                protected void dispatchDraw(Canvas canvas) {

//create the rectangle

                                RectF drawRect = new RectF();

//set the layout of rectangle

                                drawRect.set(0, 0, getMeasuredWidth(),        getMeasuredHeight());

                                canvas.drawRoundRect(drawRect, 5, 5, innerPaint);

                                canvas.drawRoundRect(drawRect, 5, 5, borderPaint);






And now run your Android application -:


Sliding effect in Android

Sliding effect in Android

Thank you for reading this article. If this article related, you have any valuable questions, suggestion and comments then write in comment box.

Leave Comment