Android SlidingDrawer 滑动抽屉效果

转载声明:http://blog.csdn.net/vestigge/article/details/8125576

效果如上图,想必大家已经在很多应用中看到过了,下面来看看用SlidingDrawer 实现滑动抽屉效果

从Android1.5开始,加入了android.widget.SlidingDrawer类

SlidingDrawer控件的一些属性:

android:allowSingleTap指示是否可以通过handle打开或关闭

  android:animateOnClick指示是否当使用者按下手柄打开/关闭时是否该有一个动画。

  android:content隐藏的内容

  android:handlehandle

 

 1 <LinearLayout   
 2     xmlns:android="http://schemas.android.com/apk/res/android"  
 3     android:layout_width="match_parent"  
 4     android:layout_height="match_parent"   
 5     android:orientation="vertical"  
 6     android:background="@drawable/f">  
 7     <TextView  
 8         android:layout_width="match_parent"  
 9         android:layout_height="wrap_content"  
10         android:gravity="center_vertical|center_horizontal"/>  
11     <SlidingDrawer  
12         android:id="@+id/slidingdrawer"  
13         android:layout_width="match_parent"  
14         android:layout_height="wrap_content"  
15         android:content="@+id/content"  
16         android:handle="@+id/handle"  
17         android:orientation="vertical" >  
18         <ImageView  
19             android:id="@id/handle"  
20             android:layout_width="wrap_content"  
21             android:layout_height="wrap_content"  
22             android:src="@drawable/music_list_btn" >  
23         </ImageView>  
24         <LinearLayout  
25             android:id="@id/content"  
26             android:layout_width="match_parent"  
27             android:layout_height="match_parent"  
28             android:background="@drawable/t">  
29             <TextView  
30                 android:layout_width="match_parent"  
31                 android:layout_height="match_parent"  
32                 android:text="隐藏的内容"/>  
33         </LinearLayout>  
34     </SlidingDrawer>  
35 </LinearLayout>  

 

通过布局文件就已经实现了上面的效果,此外SlidingDrawer还提供了一些方法:

 

 1 <span style="white-space: pre;">    </span>SlidingDrawer sd = (SlidingDrawer)findViewById(R.id.slidingdrawer);  
 2           
 3         sd.setOnDrawerOpenListener(new OnDrawerOpenListener(){  
 4             public void onDrawerOpened() {  
 5                 // TODO Auto-generated method stub  
 6             }  
 7         });  
 8         sd.setOnDrawerCloseListener(new OnDrawerCloseListener(){  
 9             public void onDrawerClosed() {  
10                 // TODO Auto-generated method stub  
11             }  
12         });  
13         sd.setOnDrawerScrollListener(new OnDrawerScrollListener(){  
14             public void onScrollEnded() {  
15                 // TODO Auto-generated method stub  
16             }  
17             public void onScrollStarted() {  
18                 // TODO Auto-generated method stub  
19             }     
20         }); 

 

 

 

 

 

 

posted @ 2013-01-26 11:48  王世桢  阅读(181)  评论(0编辑  收藏  举报