最近在研究Lanucher ,看了源码,发现了SlidingDrawer 这个类,也就是所谓的"抽屉"类。它的用法很简单,要包括handle ,和content .

  handle 就是当你点击它的时候,content 要么抽抽屉要么关抽屉。别的不多说了,具体步骤如下.

  1.新建Android 工程,命名为SlidingDrawer .

  2.准备素材,在这里我的图标是用Launcher2 里面的图标,放在drawable-hdpi 文件夹目录结构如下:

  3.设置 main.xml 布局:代码如下:

<?xml version="1.0"  encoding="utf-8"?>     
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"    
     android:orientation="vertical"    
     android:layout_width="fill_parent"    
     android:layout_height="fill_parent"    
     android:background="#808080"    
    >     
<SlidingDrawer      
    android:id="@+id/slidingdrawer"    
     android:layout_width="fill_parent"    
     android:layout_height="fill_parent"    
     android:orientation="vertical"    
    android:handle="@+id/handle"     
    android:content="@+id/content">     
    <Button     
             android:id="@+id/handle"    
             android:layout_width="88dip"    
             android:layout_height="44dip"    
             android:background="@drawable/handle"    
        />     
     <LinearLayout     
        android:id="@+id/content"    
         android:layout_width="fill_parent"    
         android:layout_height="fill_parent"    
         android:background="#00ff00">     
        <Button     
             android:id="@+id/button"    
             android:layout_width="wrap_content"    
             android:layout_height="wrap_content"    
             android:text="Button"    
        />     
        <EditText      
            android:id="@+id/editText"    
             android:layout_width="fill_parent"    
             android:layout_height="wrap_content"    
        />     
     </LinearLayout>     
</SlidingDrawer>     
</LinearLayout>     
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    android:background="#808080"  
    > 
<SlidingDrawer 
     android:id="@+id/slidingdrawer" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
    android:handle="@+id/handle" 
     android:content="@+id/content"> 
    <Button 
             android:id="@+id/handle" 
            android:layout_width="88dip" 
             android:layout_height="44dip" 
             android:background="@drawable/handle" 
        /> 
     <LinearLayout 
        android:id="@+id/content" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="#00ff00"> 
        <Button 
             android:id="@+id/button" 
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content" 
             android:text="Button" 
        /> 
        <EditText 
             android:id="@+id/editText" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
        /> 
     </LinearLayout> 
</SlidingDrawer> 
</LinearLayout>  

4.设置handle 图标的样式,在drawable 里添加handle.xml ,代码如下:

<?xml  version="1.0" encoding="utf-8"?>     
<selector  xmlns:android="http://schemas.android.com/apk/res/android">     
     <item android:state_window_focused="false"  android:state_enabled="true" android:drawable="@drawable/handle_normal"  />     
    <item android:state_pressed="true"  android:drawable="@drawable/handle_pressed" />     
    <item  android:state_focused="true" android:state_enabled="true"  android:drawable="@drawable/handle_focused" />     
    <item  android:state_enabled="true" android:drawable="@drawable/handle_normal"  />     
    <item android:state_focused="true"  android:drawable="@drawable/handle_focused" />     
</selector>     
<?xml version="1.0" encoding="utf-8"?> 
<selector  xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item android:state_window_focused="false"  android:state_enabled="true" android:drawable="@drawable/handle_normal"  /> 
    <item android:state_pressed="true"  android:drawable="@drawable/handle_pressed" /> 
    <item  android:state_focused="true" android:state_enabled="true"  android:drawable="@drawable/handle_focused" /> 
    <item  android:state_enabled="true" android:drawable="@drawable/handle_normal"  /> 
    <item android:state_focused="true"  android:drawable="@drawable/handle_focused" /> 
</selector> 

   5.运行之。将会得到如下效果:

  的比较简单呵呵, 如果想深入了解,大家看Launcher 源码吧!

更多相关文章

  1. Android自定义TTF字体
  2. Android(安卓)Material Design之Snackbar
  3. 改进Android(安卓)SlidingMenu实现QQ样式边侧滑抽屉技术
  4. 调用图灵机器人API实现Android智能机器人
  5. Android之模仿微信登陆界面(一)
  6. Android入门之TabHost,TabWidget
  7. 解决eclipse里android无法关联源码办法
  8. Android(安卓)WebView那些坑之上传文件
  9. windows中下载android源码的方法 附下载脚本

随机推荐

  1. golang可以写web吗?
  2. golang结构体怎么判断是否为空
  3. golang判断map是否存在key
  4. 2021年放弃Python选择Go的原因
  5. golang接口可以嵌套吗
  6. 运行golang程序提示进程无法启动
  7. golang mysql操作介绍
  8. golang反向代理无法访问
  9. golang项目如何部署到linux服务器
  10. go get命令下载扩展包的几点说明