Android學習筆記(二四): 多頁顯示-SlidingDrawer的使用

來源:互聯網
上載者:User

這個圖可以在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開發相關文章

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.