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

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

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

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

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

<textarea cols="50" rows="15" name="code" class="c-sharp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot; android:background=&quot;#808080&quot; &gt; &lt;SlidingDrawer android:id=&quot;@+id/slidingdrawer&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot; android:orientation=&quot;vertical&quot; android:handle=&quot;@+id/handle&quot; android:content=&quot;@+id/content&quot;&gt; &lt;Button android:id=&quot;@+id/handle&quot; android:layout_width=&quot;88dip&quot; android:layout_height=&quot;44dip&quot; android:background=&quot;@drawable/handle&quot; /&gt; &lt;LinearLayout android:id=&quot;@+id/content&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot; android:background=&quot;#00ff00&quot;&gt; &lt;Button android:id=&quot;@+id/button&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;Button&quot; /&gt; &lt;EditText android:id=&quot;@+id/editText&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;wrap_content&quot; /&gt; &lt;/LinearLayout&gt; &lt;/SlidingDrawer&gt; &lt;/LinearLayout&gt; </textarea>

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

<textarea cols="50" rows="15" name="code" class="c-sharp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt; &lt;item android:state_window_focused=&quot;false&quot; android:state_enabled=&quot;true&quot; android:drawable=&quot;@drawable/handle_normal&quot; /&gt; &lt;item android:state_pressed=&quot;true&quot; android:drawable=&quot;@drawable/handle_pressed&quot; /&gt; &lt;item android:state_focused=&quot;true&quot; android:state_enabled=&quot;true&quot; android:drawable=&quot;@drawable/handle_focused&quot; /&gt; &lt;item android:state_enabled=&quot;true&quot; android:drawable=&quot;@drawable/handle_normal&quot; /&gt; &lt;item android:state_focused=&quot;true&quot; android:drawable=&quot;@drawable/handle_focused&quot; /&gt; &lt;/selector&gt; </textarea>

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


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

更多相关文章

  1. android 各版本区别
  2. 最新Android(安卓)Studio更换应用图标方法
  3. Android高手进阶教程(十六)---Android中Intent传递对象的两种方
  4. Android利用已有控件实现自定义控件
  5. Android(安卓)按钮点击切换背景,同时修改文字颜色
  6. Android上在两个Activity之间传递Bitmap对象
  7. 基于Eclipse的Android(安卓)JNI层测试应用开发过程记录
  8. Android的selector背景选择器
  9. [Android]获取未安装的APK图标

随机推荐

  1. 有关Android(安卓)Bluetooth - OBEX OPP
  2. android控件之ProgressBar进度条
  3. Android基站定位——通过手机信号获取基
  4. Android(安卓)Notification(Android(安卓)
  5. 2018-08-17 Android(安卓)Gradle(1)
  6. 你需要知道的Android(安卓)View的测量
  7. Android(安卓)修改framework实现 全局唯
  8. Android(安卓)开发 Adb等常用指令集
  9. Android(安卓)进程状态的概念
  10. Android布局优化【面试篇】