Android drawer Effect

Source: Internet
Author: User
Although the slidingdrawer class is no longer recommended, sometimes it can be used if the effect is simple. Anyway, I may miss it, mainly because it is easy to use and can only slide up or down or left or right, in addition, the direction cannot be specified at the beginning,

Layout File

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"

Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical"
Android: Background = "#000099">

<Slidingdrawer
Android: Id = "@ + ID/slidingdrawer"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: content = "@ + ID/content"
Android: handle = "@ + id/handle"
Android: orientation = "vertical">
<ImageView
Android: id = "@ id/handle"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/lo19">
</ImageView>
<LinearLayout
Android: id = "@ id/content"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "#008800">
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: text = "hidden content"/>
</LinearLayout>
</SlidingDrawer>
<TextView
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: text = "bottom textView"
Android: textAppearance = "? Android: attr/textAppearanceLarge"
Android: gravity = "center_vertical | center_horizontal"/>
</LinearLayout>

You can slide without writing any code on the main interface,

If you want to write some methods, the following methods are used:

SlidingDrawer sd = (SlidingDrawer) findViewById (R. id. slidingdrawer );

Sd. setOnDrawerOpenListener (new OnDrawerOpenListener (){
Public void onDrawerOpened (){
// TODO Auto-generated method stub
}
});
Sd. setOnDrawerCloseListener (new OnDrawerCloseListener (){
Public void onDrawerClosed (){
// TODO Auto-generated method stub
}
});
Sd. setOnDrawerScrollListener (new OnDrawerScrollListener (){
Public void onScrollEnded (){
// TODO Auto-generated method stub
}
Public void onScrollStarted (){
// TODO Auto-generated method stub
}
});

The icon of the application on the hand machine in the lower drawer is displayed with a zoom icon in the drawer, Which is switched from the network. I think it may be useful in the future. If there is intrusion, please also inform

Layout File

<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">

<SlidingDrawer
Android: id = "@ + id/sliding"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: content = "@ + ID/allapps"
Android: handle = "@ + ID/imageviewicon"
Android: Orientation = "vertical">

<Gridview
Android: Id = "@ + ID/allapps"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "@ drawable/lo13"
Android: columnWidth = "60dp"
Android: gravity = "center"
Android: horizontalSpacing = "10dp"
Android: numColumns = "auto_fit"
Android: padding = "10dp"
Android: stretchMode = "columnWidth"
Android: verticalSpacing = "10dp"/>

<ImageView
Android: id = "@ + id/imageViewIcon"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/lo19"/>
</SlidingDrawer>

</RelativeLayout>

Operate the Activity class of the file configured above

Package com. example. t;

Import java. util. List;

Import android. OS. Bundle;
Import android. app. Activity;
Import android. content. Intent;
Import android. content. pm. ResolveInfo;
Import android. view. Menu;
Import android. view. View;
Import android. view. ViewGroup;
Import android. widget. BaseAdapter;
Import android. widget. GridView;
Import android. widget. ImageView;
Import android. widget. SlidingDrawer;
// This class compresses the icons of all applications and displays them as drawers.
Public class MainActivity extends Activity {

Private GridView gv;
Private SlidingDrawer sd;
Private ImageView iv;
Private List <ResolveInfo> apps;

/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main_2 );
LoadApps ();
Gv = (GridView) findViewById (R. id. allApps );
Sd = (s0000ingdrawer) findViewById (R. id. sliding );
Iv = (ImageView) findViewById (R. id. imageViewIcon );
Gv. setAdapter (new GridAdapter ());
Sd. setOnDrawerOpenListener (new s0000ingdrawer. OnDrawerOpenListener () // open the drawer
{
@ Override
Public void ondraweropened (){
Iv. setimageresource (R. drawable. lo19); // responds to Drawer Opening events
// Set the image to the lower
}
});
Sd. setOnDrawerCloseListener (new SlidingDrawer. OnDrawerCloseListener (){
@ Override
Public void onDrawerClosed (){
Iv. setImageResource (R. drawable. lo13); // responds to the close drawer event
}
});
}

Private void loadApps (){
Intent intent = new Intent (Intent. ACTION_MAIN, null );
Intent. addCategory (Intent. CATEGORY_LAUNCHER );
Apps = getPackageManager (). queryIntentActivities (intent, 0 );
}

Public class GridAdapter extends BaseAdapter {

Public GridAdapter (){
Super ();
}

Public int getCount (){
// TODO Auto-generated method stub
Return apps. size ();
}

Public Object getItem (int position ){
// TODO Auto-generated method stub
Return apps. get (position );
}

Public long getItemId (int position ){
// TODO Auto-generated method stub
Return position;
}

Public View getView (int position, View convertView, ViewGroup parent ){
// TODO Auto-generated method stub
ImageView imageView = null;
If (convertView = null ){
ImageView = new ImageView (MainActivity. this );
ImageView. setScaleType (ImageView. ScaleType. FIT_CENTER );
ImageView. setLayoutParams (new GridView. LayoutParams (50, 50 ));
} Else {
Imageview = (imageview) convertview;
}

Resolveinfo rI = apps. Get (position );
Imageview. setimagedrawable (Ri. activityinfo
. Loadicon (getpackagemanager ()));

Return imageview;
}
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.