2013-09-23 18 views
1

我試圖實現一個類似於Google+的用戶界面,其中android活動將有兩個滑出抽屜,左邊主要一個,這是主菜單。第二個從右側,這是我的通知。然而,看着DrawerLayout,我可以看到它不支持。任何想法的Google+應用程序如何實現它?主要和輔助抽屜的Android活動

在此先感謝

回答

3

我已經想通了如何使用以下佈局

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- android:layout_gravity="start" tells DrawerLayout to treat 
    this as a sliding drawer on the left side for left-to-right 
    languages and on the right side for right-to-left languages. 
    The drawer is given a fixed width in dp and extends the full height of 
    the container. A solid background is used for contrast 
    with the content view. --> 
<ListView 
    android:id="@+id/left_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" 
    android:background="#111"/> 
<ListView 
    android:id="@+id/right_drawer" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="right" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" 
    android:background="#111"/> 
</android.support.v4.widget.DrawerLayout> 

搞怪的文檔中沒有提到這一點做出來,當庫第一次如果有兩個以上的孩子存在,DrawerLayout會拋出異常。

0

DrawerLayout在單個佈局文件中不支持2個抽屜。兩者都應爲它們的layout_gravity屬性(「左」和「右」)獲得不同的值。

例片段:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <!-- Main content --> 

    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/nav_left" 
     android:layout_width="@dimen/nav_left_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="left"> 

     <!-- Content of your left drawer --> 

    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/nav_right" 
     android:layout_width="@dimen/nav_right_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="right"> 

     <!-- Content of your right drawer --> 

    </FrameLayout> 

</android.support.v4.widget.DrawerLayout> 

+0

沒有提及能夠在這裏使用DrawerLayout的兩個抽屜http://developer.android.com/training/implementing-navigation/nav-drawer.html。你有關於如何實現的更多信息?謝謝! –