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

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

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

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

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

<?xml version="1.0"  encoding="utf-8"?>     
     android:orientation="vertical"    
     android:layout_width="fill_parent"    
     android:layout_height="fill_parent"    
     android:background="#808080"    
    >     
    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">     
                  android:id="@+id/handle"    
             android:layout_width="88dip"    
             android:layout_height="44dip"    
             android:background="@drawable/handle"    
        />     
             android:id="@+id/content"    
         android:layout_width="fill_parent"    
         android:layout_height="fill_parent"    
         android:background="#00ff00">     
                      android:id="@+id/button"    
             android:layout_width="wrap_content"    
             android:layout_height="wrap_content"    
             android:text="Button"    
        />     
                     android:id="@+id/editText"    
             android:layout_width="fill_parent"    
             android:layout_height="wrap_content"    
        />     
          
     
    
<?xml version="1.0" encoding="utf-8"?> 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    android:background="#808080"  
    > 
     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"> 
                  android:id="@+id/handle" 
            android:layout_width="88dip" 
             android:layout_height="44dip" 
             android:background="@drawable/handle" 
        /> 
             android:id="@+id/content" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="#00ff00"> 
                      android:id="@+id/button" 
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content" 
             android:text="Button" 
        /> 
                      android:id="@+id/editText" 
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content" 
        /> 
    
 
 
 

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

<?xml  version="1.0" encoding="utf-8"?>     
     
          
         
         
         
         
    
<?xml version="1.0" encoding="utf-8"?> 
 
      
     
     
     
     
 

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

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

更多相关文章

  1. Android日历(Calendar,dataPicker)
  2. android性能测试bootchart篇
  3. Android之3D物理引擎
  4. Android高手进阶教程(八)之----Android(安卓)Widget开发案例(世
  5. Android(安卓)图表应用 解决方案
  6. android recovery模式及ROM制作
  7. android学习六(android中四种基本布局)
  8. ListView有背景图片或背景颜色,那么在滑动ListView的时候,ListView
  9. Android(安卓)高手进阶教程(十三)之----Android(安卓)数据库SQLi

随机推荐

  1. Android4.4系统源代码百度网盘下载
  2. 读书笔记(一)---GoogleAndroid开发入门指南
  3. android中去掉标题栏和状态栏
  4. 【Android學習專題】搭建Android NDK环境
  5. Android 5.1源代码与Nexus设备工厂镜像下
  6. RatingBar
  7. android timed gpio (linux 3.0.0) 受时
  8. Android -- Sqlite事务
  9. Android ListView 去除边缘阴影、选中色
  10. 转:Android 发送短信的方法