|
|
這個圖可以在Android的doc中,誤操作,將原來圖片刪去,所以上面只是範例,沒有透明效果 |
SlideDrawer是多個(兩個頁面)的一種顯示方式。如上左圖所示,普通的,我們顯示Hello的Label,當我們按下面的SlidingDrawer的ImageView,即右圖所示表徵圖時,可以將SlideDrawer的內容顯示上去,如中圖。SlidingDrawer可以在Open和Close兩個狀態之間切換。Open時覆蓋,不是所有的Layout都能支援這種疊加覆蓋,作為SlidingDrawer的container,例如LinearLayout就不可以,一般使用RelativeLayout和FrameLayout。下面是例子的XML檔案,採用了FrameLayout作為容器:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF8888CC">
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textStyle="bold"
android:gravity="center"
android:text="Hello" /> <!-- 我們採用了簡單的TextView表示原本頁的內容,在SlidingDrawer處於Close時顯示,如左圖-->
<SlidingDrawer android:id="@+id/c96_drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<!-- SlidingDrawer中包含兩個重要參數handle和content,類似於Tab的標籤和內容,我們需要在這裡設定相關的id,以便引用-->
android:handle="@+id/c96_handle"
android:content="@+id/c96_content" >
<ImageView android:id="@id/c96_handle"
<!-- 和SlidingDrawer的handle的id相一致,一般而言會是一個Image,當然我們也可以設定為Button等其他,只是美觀上欠佳。-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tray_handle_normal" />
<Button android:id="@id/c96_content" <!-- 和SlidingDrawer的content的id相一致,這裡我們簡單用Button來處理-->
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="I am in Here" />
</SlidingDrawer>
</FrameLayout>
源檔案無須特別處理,對於SlidingDrawer,可以open(), close() , toggle() ,也可以採用動畫的方式anmiateOpen(),animateClose()和animateToggle()。可以在XML中設定android:animateOnClick ="true" ,預設為真。
我們還可以設定lock()和unlock()。
我們可以對SlidingDrawer的事件進行監聽:openen,closed,scrolled(使用者拖拽標籤)。例如:setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener)。
相關連結:我的Andriod開發相關文章