推荐安卓开发神器(里面有各种UI特效和android代码库实例)

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

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

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

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



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

view plaincopy to clipboardprint?<?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 ,代码如下:

view plaincopy to clipboardprint?<?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.运行之。将会得到如下效果:



更多相关文章

  1. android在布局中动态增加view时的层级控制
  2. 升级代码的大概设计
  3. OpenCore 的代码结构
  4. Android下使用TinyXml读取xml配置文件(Cocos2d-x游戏开发)
  5. Unexpected namespace prefix "xmlns" found for tag LinearLayo
  6. 几行代码看程序员的水平——Android文件命名规范
  7. Android(安卓)高手进阶教程(十四)之----Android(安卓)Location的
  8. 图解Android源代码下载指南
  9. Android高手进阶教程(二)之 ----Android(安卓)Launcher抽屉类Sli

随机推荐

  1. javaapiOpenCV4Android--使用java api做
  2. Android(安卓)Camera(一)
  3. Android极速开发框架One,只需59秒即可!
  4. Android(安卓)View 事件分发机制 源码解
  5. Android基于MQTT实现发布消息与监听topic
  6. android中高级必会面试知识及答案(继续更
  7. TableLayout布局表格列按比例切分屏幕
  8. android 获取文件大小
  9. Android仿微信源码下载
  10. android framework增加/删除类