`
que2010
  • 浏览: 71996 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

实现Launcher的抽屉效果

阅读更多

android 的 launcher 有一个抽屉效果,可以有拉出和关闭的效果. 这里主要讨论如何实现这种效果.

 
将slidingdraw 控件添加到相关的layout中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

        <SlidingDrawer
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:handle="@+id/handle"
            android:content="@+id/content" >
            <Button
                android:id="@+id/handle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/handle" />
            <LinearLayout
                android:id="@+id/content"
                android:layout_width="fill_parent"
                android:orientation="vertical"
                android:layout_height="wrap_content">
                <TextView
                    android:width="wrap_content"
                    android:height="wrap_content"
                    android:text="@string/hello"
            </LinearLayout>
        </SlidingDrawer>

</LinearLayout>
 
有几个属性要注意, 先说slidingdrawer的属性.
android:handle="@+id/handle" 这个属性指定的是那一个控件的相应将启动这个SlidingDraw 这里是一个Button控件
android:content="@+id/content" 这个属性指定的SlidingDrawer的内容,若是SlidingDraw启动后, 应该调出那个内容,这里是一个linelayout
除此之外, Button里面设置了一个selector, android:background="@drawable/handle", 这样在不同的响应中就有不同的背景
<?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/tray_handle_normal" />
    <item android:state_pressed="true" android:drawable="@drawable/tray_handle_pressed" />
    <item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/tray_handle_selected" />
    <item android:state_enabled="true" android:drawable="@drawable/tray_handle_normal" />
    <item android:state_focused="true" android:drawable="@drawable/tray_handle_selected" />
</selector>
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics