Android   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了java – 如何在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://scheR_895_11845@as.android.com/apk/res/android"
xmlns:tools="http://scheR_895_11845@as.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://scheR_895_11845@as.android.com/apk/res/android"
xmlns:tools="http://scheR_895_11845@as.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>

祝你好运!希望有所帮助!

大佬总结

以上是大佬教程为你收集整理的java – 如何在Android DrawerLayout中使用两个片段全部内容,希望文章能够帮你解决java – 如何在Android DrawerLayout中使用两个片段所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: