Android側(cè)滑菜單控件DrawerLayout使用詳解-創(chuàng)新互聯(lián)

DrawerLayout是Android V4包下一個(gè)帶有側(cè)滑功能的布局控件,可以根據(jù)手勢(shì)展開(kāi)與隱藏側(cè)邊欄,也可以隨著側(cè)邊欄的點(diǎn)擊改變主界面區(qū)的內(nèi)容。并且只需要按照DrawerLayout規(guī)定的布局格式進(jìn)行布局,即可實(shí)現(xiàn)左右側(cè)滑效果。

創(chuàng)新互聯(lián)建站于2013年開(kāi)始,先為托里等服務(wù)建站,托里等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為托里企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

一、約定的抽屜布局


  DrawerLayout的布局一般分為三個(gè)部分:第一部分為主界面內(nèi)容布局,第二部分為左邊側(cè)滑界面布局,第三部分為右邊側(cè)滑界面布局。那么系統(tǒng)是怎么區(qū)分左邊側(cè)滑和右邊側(cè)滑的代碼塊的呢?請(qǐng)注意DrawerLayout布局中側(cè)滑部分的代碼塊必須指定android:layout_gravity屬性,layout_gravity="start/left"代表左邊側(cè)滑,layout_gravity="end/right"代表右邊側(cè)滑。在官方文檔中推薦DrawerLayout最好作為界面的根布局,否則可能會(huì)出現(xiàn)觸摸事件被屏蔽的問(wèn)題。DrawerLayout中主內(nèi)容區(qū)的布局要放到最頂層,接著放置左邊側(cè)滑界面布局,最后放置右邊側(cè)滑界面布局。類似布局如下:


<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:id="@+id/drawerlayout" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  tools:context="com.administer.drawlayoutdemo.MainActivity"> 
 
  <RelativeLayout 
    android:id="@+id/relativelayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button 
      android:id="@+id/left_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="開(kāi)啟左邊菜單欄" /> 
 
    <Button 
      android:id="@+id/right_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="開(kāi)啟右邊菜單欄" 
      android:layout_alignParentRight="true"/> 
  </RelativeLayout> 
 
  <RelativeLayout 
    android:id="@+id/left" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="left" 
    android:background="#f00"> 
 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="左邊布局" /> 
 
  </RelativeLayout> 
 
  <RelativeLayout 
    android:id="@+id/right" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="right" 
    android:background="#00f"> 
 
    <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="右邊布局" /> 
  </RelativeLayout> 
 
</android.support.v4.widget.DrawerLayout> 

文章標(biāo)題:Android側(cè)滑菜單控件DrawerLayout使用詳解-創(chuàng)新互聯(lián)
鏈接分享:http://bm7419.com/article8/cdehop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)網(wǎng)站排名、網(wǎng)站收錄、App開(kāi)發(fā)云服務(wù)器、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司