<LinearLayoutxmlns: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:orientation= "vertical" > <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" /> <SlidingdrawerAndroid:id= "@+id/sd"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Horizontal"Android:handle= "@+id/img"set the handle android:content= "@+id/lin"set the domain Android:background= "#fd8"> <ImageViewAndroid:id= "@+id/img"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/star_full" /> <LinearLayoutAndroid:id= "@+id/lin"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"> </LinearLayout> </Slidingdrawer></LinearLayout>
Packagecom.example.sliding;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.ImageView;Importandroid.widget.LinearLayout;ImportAndroid.widget.ListView;ImportAndroid.widget.SlidingDrawer;ImportAndroid.widget.Toast;ImportAndroid.widget.SlidingDrawer.OnDrawerCloseListener;ImportAndroid.widget.SlidingDrawer.OnDrawerOpenListener;ImportAndroid.widget.SlidingDrawer.OnDrawerScrollListener; Public classMainactivityextendsActivity {PrivateListView LV; PrivateSlidingdrawer SD; PrivateLinearLayout Lin; PrivateImageView img; Privatestring[] data = {"One", "one", "one", "three"}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); LV=NewListView ( This); Lv.setadapter (NewArrayadapter<string> ( This, Android. R.layout.simple_list_item_1,data)); SD=(Slidingdrawer) Findviewbyid (R.ID.SD); Lin=(LinearLayout) Findviewbyid (R.id.lin); IMG=(ImageView) Findviewbyid (r.id.img); Lin.addview (LV); //window opensSd.setondraweropenlistener (NewOndraweropenlistener () {@Override Public voidondraweropened () {img.setimageresource (r.drawable.star_empty); } }); //window CloseSd.setondrawercloselistener (NewOndrawercloselistener () {@Override Public voidondrawerclosed () {//TODO auto-generated Method StubImg.setimageresource (r.drawable.star_full); } }); Sd.setondrawerscrolllistener (NewOndrawerscrolllistener () {@Override Public voidonscrollstarted () {//TODO auto-generated Method StubToast.maketext (mainactivity. This, "Swipe to start", 1000). Show (); } @Override Public voidonscrollended () {//TODO auto-generated Method StubToast.maketext (mainactivity. This, "Sliding End", 1000). Show (); } }); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }}
Slidingdrawer sliding window