【问题标题】:Aligning LinearLayout to the bottom of a DrawerLayout将 LinearLayout 与 DrawerLayout 的底部对齐
【发布时间】:2015-12-27 10:06:41
【问题描述】:

我已经在我的应用程序的主要 XML 布局中实现了一个 DrawerLayout - 我已经创建了一个填充屏幕底部的页脚(基本上是一个水平的 [navigation-ish] 栏)。问题是-它不断出现在屏幕顶部...我尝试使用android:layout_gravity="bottom"android:layout_weight="1.0"android:baselineAligned="false",如此处所述:http://sandipchitale.blogspot.com/2010/05/linearlayout-gravity-and-layoutgravity.html 但是我似乎仍然无法从中获取页脚出现在布局的顶部。

欢迎提出任何建议:

XML 片段:

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



    ...



        <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:orientation="horizontal" >
    </LinearLayout>

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

完整的 XML 源代码:

http://pastebin.com/67cHtwJ1

截图:

【问题讨论】:

    标签: android xml android-layout android-layout-weight layout-gravity


    【解决方案1】:

    您应该将layout_gravity:bottom 应用于LinearLayout,而不是DrawerLayout。 layout_ 前缀让子级告诉父级它希望如何布局、定位等。android:gravity 应应用于父级视图并用于定位其所有子级。

    【讨论】:

    • 我尝试了您的解决方案并最终得到: ava.lang.IllegalStateException: Child android.widget.LinearLayout{422112e0 V.E..... ......I. 0,0-0,0 #7f0800ab app:id/footer} 在索引 7 处没有有效的 layout_gravity - 必须是 Gravity.LEFT、Gravity.RIGHT 或 Gravity.NO_GRAVITY - 有什么建议吗? pastebin.com/hXRPnUHy(感谢您的帮助 [顺便说一句 - 我喜欢这个用户名 - 我有两代家庭成员在 NASA 工作])
    • 我正在仔细查看代码,看看我还能做什么......(无论如何,我都感谢你的洞察力):)
    • 啊哈!我需要将它包装在 RelativeLayout 中并分配 android:layout_alignParentBottom="true" - 但我终于让它工作了 - 谢谢先生! (
    • 有趣。似乎 DrawerLayout 不喜欢看到带有layout_gravity 的孩子除了左或右之外的任何东西。不过,RelativeLayout 听起来并不是一个糟糕的解决方案。不过,您可能不想将我的解决方案标记为已接受,因为它实际上并没有解决您的问题;)
    • 另外,我认为您应该将主要内容放在“content_frame”FrameLayout 中,而不是放在 ListView 之后。研究这篇文章以更好地了解DrawerLayout 的结构。 developer.android.com/training/implementing-navigation/…
    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 2019-07-03
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多