java – 如何在Android DrawerLayout中使用两个片段
发布时间:2020-12-15 04:12:13 所属栏目:Java 来源:网络整理
导读:我尝试使用 Android NavigationDrawe – http://developer.android.com/training/implementing-navigation/nav-drawer.html 我有一个活动和两个片段. 我的主要问题是android.support.v4.widget.DrawerLayout中的布局. 一个片段使用-content_frame和其他 – c
我尝试使用
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> 显示两个片段,但彼此显示. screenshot 解决方法
如果我正确理解您的问题,您希望在顶部有一个片段,并且您希望第二个片段作为屏幕上的页脚.目前还不清楚你是否想要滚动,所以我不会假设. 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> 祝你好运!希望有所帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |