`

Android Launcher抽屉类SlidingDrawer的使用

阅读更多
最近在研究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> 
分享到:
评论

相关推荐

    Android Launcher抽屉类SlidingDrawer的使用(源码)

    Aj_01 来自:http://blog.csdn.net/Android_Tutor/archive/2010/04/14/5486804.aspx 测试:Android Launcher抽屉类SlidingDrawer的使用!

    Android高手进阶教程

    本文档介绍ANDROID常用编程及进阶编程,比如一些常用的命令,Android Launcher抽屉类SlidingDrawer的使用等等一些高级用法。

    Android高手进阶教程.pdf

    Android高手进阶教程.pdf,本书需要读者有一定的android基础,主要内容:Android常用名令集锦;...Android Launcher抽屉类SlidingDrawer 的使用; Android 中MenuInflater的使用(布局定义菜单)····

    android 抽屉从左拉出 slidingdrawer

    界面,实现一个layout或任何控件的向右拉出,向左收回效果。slidingdrawer的变形。在eclipse可直接运行。

    Android高手进阶教程与Android基础教程

    Android高手进阶教程之----Android Launcher抽屉类SlidingDrawer的使用.doc Android高手进阶教程之----Android Location的使用!! .doc Android高手进阶教程之----Android PopupWindow的使用!!! .doc Android高手...

    androidSlidingDrawer 抽屉效果

    SlidingDrawer是自SDK 1.5才新加入的,实现Launcher的抽屉效果。SlidingDrawer配置上采用了水平展开或垂直展开两种(android:orientation)方式,在XML里必须指定其使用的android:handle与android:content,前者委托...

Global site tag (gtag.js) - Google Analytics