当前位置:操作系统 > 安卓/Android >>

android抽屉效果

SlidingDrawer类虽然已经不推荐使用了,但有时如果效果简单的话用用也无妨,反正我有有点怀念,主要是它使用简单,只能上下或者左右滑动,而且刚开始的时候,方向不能指定,
布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical"
    android:background="#000099">
   
    <SlidingDrawer
        android:id="@+id/slidingdrawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:content="@+id/content"
        android:handle="@+id/handle"
        android:orientation="vertical" >
        <ImageView
            android:id="@id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/lo19" >
        </ImageView>
        <LinearLayout
            android:id="@id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#008800">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="隐藏的内容"/>
        </LinearLayout>
    </SlidingDrawer>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="bottom textView"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical|center_horizontal"/>
</LinearLayout>


在主界面中不写什么代码就可以滑了,

如果要写一些方法,主要是下面几个方法

SlidingDrawer sd = (SlidingDrawer)findViewById(R.id.slidingdrawer);
        
        sd.setOnDrawerOpenListener(new OnDrawerOpenListener(){
            public void onDrawerOpened() {
                // TODO Auto-generated method stub
            }
        });
        sd.setOnDrawerCloseListener(new OnDrawerCloseListener(){
            public void onDrawerClosed() {
                // TODO Auto-generated method stub
            }
        });
        sd.setOnDrawerScrollListener(new OnDrawerScrollListener(){
            public void onScrollEnded() {
                // TODO Auto-generated method stub
            }
            public void onScrollStarted() {
                // TODO Auto-generated method stub
            }   
        });

下面这抽屉把手机上的应用程序的图标在抽屉中以缩小的图标来显示,这是转自网络的, 我觉得可能以后有用就收藏到此了,如有侵仅,还请告知

布局文件

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" > 
     
        <SlidingDrawer 
            android:id="@+id/sliding" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:content="@+id/allApps" 
            android:handle="@+id/imageViewIcon" 
            android:orientation="vertical" > 
     
            <GridView 
                android:id="@+id/allApps" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:background="@drawable/lo13" 
                android:columnWidth="60dp" 
                android:gravity="center" 
                android:horizontalSpacing="10d

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,