Tuesday, 7 May 2013

SlidingDrawer in Android Example

Sliding Drawer :


This class was deprecated in API level 17.
This class is not supported anymore. It is recommended you base your own implementation on the source code for the Android Open Source Project if you must use it in your application.

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:

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: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=".MainActivity" >

<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/content" android:allowSingleTap="true"
android:handle="@+id/handle" >

<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/up" />

<LinearLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
</SlidingDrawer>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/slidingDrawer1"
android:layout_alignTop="@+id/slidingDrawer1"
android:layout_marginLeft="73dp"
android:gravity="center"
android:text="Sliding drawer example" />

</RelativeLayout>


MainActivity.java
package com.example.slidingdrawer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

public class MainActivity extends Activity {
SlidingDrawer drawer;
Button button;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer=(SlidingDrawer)findViewById(R.id.slidingDrawer1);
button=(Button)findViewById(R.id.handle);
drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
// TODO Auto-generated method stub
button.setBackgroundResource(R.drawable.down);
}
});
drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
// TODO Auto-generated method stub
button.setBackgroundResource(R.drawable.up);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

Screen Shot:


7 comments:

  1. Sometime few such blogs become very helpful while getting relevant and new information related to your targeted area. As I found this blog and appreciate the information delivered to my database.
    Php projects with source code
    Online examination system in php
    Student management system in php
    Php projects for students
    Free source code for academic
    Academic projects provider in nashik
    Academic project free download

    ReplyDelete
  2. You Have Been Declined for Health Insurance in California, Now What? By Dennis Alexander. Boost DA upto 35+ at cheapest
    Boost DA upto 45+ at cheapest . ArticleShare this article on FacebookShare this article on TwitterShare this article on LinkedinShare this article

    ReplyDelete
  3. Many businesses which are hoping to increase their online presence are hiring an SEO company or using SEO services well to gain every single benefit while achieving their goals. # BOOST Your GOOGLE RANKING.It’s Your Time To Be On #1st Page
    Our Motive is not just to create links but to get them indexed as will
    Increase Domain Authority (DA).We’re on a mission to increase DA PA of your domain
    High Quality Backlink Building Service
    1000 Backlink at cheapest
    50 Free Backlink
    Although attempting to learn SEO yourself is a good idea as well as a tempting one, there are high chances you might implement SEO techniques wrongly because they need months and years of experience.

    ReplyDelete
  4. Even if you are armed with an abundance of knowledge in SEO, you may still need the services of a professional SEO company. Having strong knowledge of SEO is hardly sufficient in some cases. 2000 Backlink at cheapest
    5000 Backlink at cheapest
    Boost DA upto 15+ at cheapest
    Boost DA upto 25+ at cheapest
    Boost DA upto 35+ at cheapest
    Boost DA upto 45+ at cheapest
    Even if you are doing your best to attempt to obtain a good ranking for your website, you might still wind up wondering why your website is simply not doing well.

    ReplyDelete

Call web services easily

get source code from here, Download