2016-02-08 82 views

回答

1

「有可能嗎?」
Ans:YES

「我應該用什麼庫來實現這個?」

答案:在android sdk中的導航抽屜將完美工作。

官方文件:http://developer.android.com/training/implementing-navigation/nav-drawer.html

DrawerLayout類是一個子類的ViewGroup,這意味着它有一個視圖組的所有功能。我們不僅限於列表視圖,但我們可以在DrawerLayout內添加任何類型的視圖。

例子:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<!-- The main content view --> 
<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/holo_green_dark"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Content of drawer" 
     android:textColor="@android:color/holo_red_dark" 
     android:textSize="24sp" 
     /> 

</FrameLayout> 
<!-- The navigation drawer --> 
<RelativeLayout 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="#12D" 
    > 

    <TextView 
     android:id="@+id/drawer_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:text="Custom view" 
     android:textColor="@android:color/secondary_text_light" 
     android:textSize="24sp" 
     android:textStyle="bold" 
     /> 

</RelativeLayout> 

輸出:

enter image description here

相關問題