Learn Android<slidingdrawer implicit drawer from scratch. 33 .>

Source: Internet
Author: User

Slidingdrawer is a drawer-type component that, when the user chooses to open the drawer, gets some "assemblies" that can be used, so that when a single interface is placed on multiple components, using this component can be a good solution to the problem of tight layout space. The definition of the Slidingdrawer class is as follows:Ava.lang.Object   ? Android.view.View      ? Android.view.ViewGroup        ? Android.widget.SlidingDrawer
Common Methods
1 public void Open () Ordinary Open the hidden drawer
2 public void Close () Ordinary Close the hidden drawer
3 public void Lock () Ordinary To lock the Assembly view
4 public void Unlock () Ordinary Release lock
5 Public View getcontent () Ordinary Get the assembly view you set
6 Public View GetHandle () Ordinary Get the action button view set
7 public boolean ismoving () Ordinary Are you sliding
8 public boolean isopened () Ordinary Whether to open
9 Public void Setondraweropenlistener (slidingdrawer.ondraweropenlistener ondraweropenlistener) Ordinary Trigger event when opening drawer assembly
10 Public void Setondrawercloselistener (slidingdrawer.ondrawercloselistener Ondrawercloselistener) Ordinary Trigger event when drawer assembly is closed
11 Public void Setondrawerscrolllistener (slidingdrawer.ondrawerscrolllistener Ondrawerscrolllistener) Ordinary Trigger event when moving drawer assembly


XML file

<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android "    android:id=" @+id/mylayout "    android:layout_width=" fill_parent "    android:layout_height= "Fill_parent"     android:orientation= "vertical" >    <slidingdrawer         android:id= "@+id/slidingdrawer"         android:layout_width= "Fill_ Parent "        android:layout_height=" fill_parent "        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"     &NBSP;       android:src= "@drawable/close"/>        <LinearLayout            android:id= ' @+id/content '             android:layout_width= ' Fill_ Parent "            android:layout_height=" wrap_content "          & nbsp android:orientation= "vertical" >                    </ linearlayout>        </SlidingDrawer></LinearLayout></span>


java files
<span style= "FONT-SIZE:18PX;" >package Com.example.slidingdrawer;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.widget.arrayadapter;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.listview;import Android.widget.slidingdrawer;import Android.widget.slidingdrawer.ondrawercloselistener;import Android.widget.SlidingDrawer.OnDrawerOpenListener; Import Android.widget.slidingdrawer.ondrawerscrolllistener;import Android.widget.toast;public class MainActivity Extends Activity {private slidingdrawer slidingdrawer;private ImageView handle;private String data[]={"Save Data", "Update Status", " Personal mood "," personal level "," More Information "," "," more ... "};//listview data @overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); LinearLayout layout = (linearlayout) Super.findviewbyid (r.id.content); ListView listview=new ListView (This); Listview.setadapter (New Arrayadapter<string> (This, Android. R.layout.simple_expandable_list_item_1,data));//Set Adapterlayout.addview (ListView); this.handle= (ImageView) This.findviewbyid (R.id.handle); this.slidingdrawer= (Slidingdrawer) This.findviewbyid (R.id.slidingdrawer); This.slidingDrawer.setOnDrawerCloseListener (New Ondrawercloselistener () {@Overridepublic void ondrawerclosed () {// TODO auto-generated Method Stubtoast.maketext (mainactivity.this, "menu Off", 2). Show (); Handle.setimageresource ( R.drawable.close);}); This.slidingDrawer.setOnDrawerOpenListener (New Ondraweropenlistener () {@Overridepublic void ondraweropened () {// TODO auto-generated Method Stubtoast.maketext (mainactivity.this, "menu Open", 2). Show (); Handle.setimageresource ( R.drawable.open);}); This.slidingDrawer.setOnDrawerScrollListener (New Ondrawerscrolllistener () {@Overridepublic void onscrollstarted () { TODO auto-generated Method Stubtoast.maketext (Mainactivity.this, "dragging", 2). Show (); @Overridepublic void onscrollended () {//TODO auto-generated Method stub}});}} </span> 



We use the Slidingdrawer and GridView combination to make an implicit menu effect
Import the pictures you used
XML File
<span style= "FONT-SIZE:18PX;" ><?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/    Res/android "android:id=" @+id/mylayout "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:orientation= "vertical" > <slidingdrawer android:id= "@+id/slidingdrawer" Android:layout_wid Th= "Fill_parent" android:layout_height= "fill_parent" 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/clo            Se "/> <linearlayout android:id=" @+id/content "android:layout_width=" Fill_parent "            android:layout_height= "wrap_content" android:orientation= "vertical" > <gridview    Android:id= "@+id/gridview" android:layout_width= "fill_parent" android:layout_height= "fil L_parent "android:numcolumns=" 4 "//number of data per line android:stretchmode=" ColumnWidth "and roid:verticalspacing= "70DP" >//line spacing </GridView> </LinearLayout> </slidingdrawer>& Lt;/linearlayout></span>


java files


after opening



Implicit drawer assembly in the development of more commonly used to, will be simple, I hope you learn to master
next section forecastpopupwindow pop-up window

Learn Android<slidingdrawer implicit drawer from scratch. 33 .>

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.