繁体   English   中英

DrawerLayout的底部项目

[英]Bottom item on the DrawerLayout

我正在尝试做同样的事情@lnamdar在这个问题中问( 带有固定菜单项的抽屉布局 )。 我正在尝试更好地解释他们的解决方案。

我正在尝试:

<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"
android:background="@android:color/black">

<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/transparent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/black"
        android:text="This is the footer text"/>

</RelativeLayout>

<!-- The navigation drawer -->
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:background="@android:color/black"/>

但这导致列表视图不显示,并且当我切换打开/关闭时,我看到的唯一内容是页脚。 我试图将listView和footer textView都放在RelativeLayout内,但随后在Drawer Layout类上使用的Layout Params上出现ClassCastException崩溃。

谢谢你的帮助!

他们对RelativeLayout的尝试给出了意外的结果,因为它不在内容框架内。 解释非常简单,因为RelativeLayout是包含菜单项的ListView父级,我们将重力移到了它,而不是使用具有相同重力的ListView 这是我所做的:

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

    <TextView

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="?android:attr/activatedBackgroundIndicator"
        android:gravity="center_vertical"
        android:id="@+id/logout_item"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="@string/logout"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="#fff" />

</FrameLayout>
</RelativeLayout>

不要忘记运行HierarchyViewer来摆脱不必要的ViewGroup。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM