Android SlidingDrawer 滑動抽屜效果

  \

20121022031344272.png (386×570)

效果如上圖,想必你們已經在不少應用中看到過了,下面來看看用SlidingDrawer 實現滑動抽屜效果html

從Android1.5開始,加入了android.widget.SlidingDrawer類java

SlidingDrawer控件的一些屬性:android

    android:allowSingleTap 指示是否能夠經過handle打開或關閉
    android:animateOnClick 指示是否當使用者按下手柄打開/關閉時是否該有一個動畫。
    android:content 隱藏的內容
  android:handle handle (控制)web

佈局文件:佈局

<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="@drawable/f"> 
    <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_vertical|center_horizontal"/> 
    <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/music_list_btn" > 
        </ImageView> 
        <LinearLayout 
            android:id="@id/content" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:background="@drawable/t"> 
            <TextView 
                android:layout_width="match_parent" 
                android:layout_height="match_parent" 
                android:text="隱藏的內容"/> 
        </LinearLayout> 
    </SlidingDrawer> 
</LinearLayout>

經過佈局文件就已經實現了上面的效果,此外SlidingDrawer還提供了一些方法:動畫

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 
            }    
        });
相關文章
相關標籤/搜索