Android高手进阶教程(二)之----Android(安卓)Launcher抽屉类SlidingDrawer的使用!
16lz
2022-07-03
最近在研究Lanucher ,看了源码,发现了SlidingDrawer 这个类,也就是所谓的"抽屉"类。它的用法很简单,要包括handle ,和content .
handle 就是当你点击它的时候,content 要么抽抽屉要么关抽屉。别的不多说了,具体步骤如下.
1.新建Android 工程,命名为SlidingDrawer .
2.准备素材,在这里我的图标是用Launcher2 里面的图标,放在drawable-hdpi 文件夹目录结构如下:
3.设置main.xml 布局:代码如下:
[c-sharp]view plaincopy- <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#808080"><SlidingDrawerandroid:id="@+id/slidingdrawer"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:handle="@+id/handle"android:content="@+id/content"><Buttonandroid:id="@+id/handle"android:layout_width="88dip"android:layout_height="44dip"android:background="@drawable/handle"/><LinearLayoutandroid:id="@+id/content"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#00ff00"><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button"/><EditTextandroid:id="@+id/editText"android:layout_width="fill_parent"android:layout_height="wrap_content"/></LinearLayout></SlidingDrawer></LinearLayout>
4.设置handle 图标的样式,在drawable 里添加handle.xml ,代码如下:
[c-sharp]view plaincopy- <?xmlversion="1.0"encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_window_focused="false"android:state_enabled="true"android:drawable="@drawable/handle_normal"/><itemandroid:state_pressed="true"android:drawable="@drawable/handle_pressed"/><itemandroid:state_focused="true"android:state_enabled="true"android:drawable="@drawable/handle_focused"/><itemandroid:state_enabled="true"android:drawable="@drawable/handle_normal"/><itemandroid:state_focused="true"android:drawable="@drawable/handle_focused"/></selector>
5.运行之。将会得到如下效果:
的比较简单呵呵,如果想深入了解,大家看Launcher 源码吧!
更多相关文章
- android EditText设置不可写
- Android(安卓)P SystemUI之StatusBar UI布局status_bar.xml解析
- android 创建桌面快捷方式 、插件
- Android(安卓)Activity的启动
- APP开发实战94-Vector静态图的使用
- Android(安卓)开发中的倒计时
- Gradle多渠道打包
- [APP] Android(安卓)开发笔记 006-使用短信验证SDK进行短信验证
- Android(安卓)5.x特性概览二