[英]How use two fragment in Android DrawerLayout
我嘗試使用Android NavigationDrawe - http://developer.android.com/training/implementing-navigation/nav-drawer.html我有一個活動和兩個片段。 我的主要問題是android.support.v4.widget.DrawerLayout中的布局。 一個片段使用-content_frame和其他 - content_footer。 此元素將位於底部(height - wrap_content)。 我嘗試了不同的變化,但沒有奏效。 所有例子都有一個片段。 我做錯了什么? 謝謝
我的主要布局文件。 用這個節目一個片段。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
>
</FrameLayout>
<FrameLayout
android:id="@+id/content_footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
>
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/abs__bright_foreground_disabled_holo_light"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
當改為:
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
>
</RelativeLayout>
<RelativeLayout
android:id="@+id/content_footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
>
</RelativeLayout>
</FrameLayout>
顯示兩個片段,但彼此顯示。 截圖
如果我正確理解您的問題,您希望在頂部有一個片段,並且您希望第二個片段作為屏幕上的頁腳。 目前還不清楚你是否想要滾動,所以我不會假設。 DrawerLayout實際上在根據我的知識布置元素方面做的並不多,所以我建議在DrawerLayout中放置一個布局來根據需要定位片段。 做一些類似於我將在下面提到的未經測試的代碼:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="80" >
</FrameLayout>
<FrameLayout
android:id="@+id/content_footer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20" >
</FrameLayout>
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/abs__bright_foreground_disabled_holo_light"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
祝你好運! 希望有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.