Android 如何使我的布局处于活动的底部

Android 如何使我的布局处于活动的底部,android,xml,Android,Xml,您好,我正在开发一款ios风格的应用程序,它的底部有一个布局,我似乎无法让这个布局位于底部 这是我的密码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_w

您好,我正在开发一款ios风格的应用程序,它的底部有一个布局,我似乎无法让这个布局位于底部

这是我的密码:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10"
    tools:context=".MyActivity"
    tools:ignore="UselessLeaf,ContentDescription" >


    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="5dp"
        android:layout_weight="7" >
    </android.support.v4.view.ViewPager>

    <com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/pagerIndicator"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:padding="3dp" />



        <LinearLayout
            android:id="@+id/layout11"
            android:layout_width="match_parent"
            android:layout_height="30dip"
            android:background="@drawable/dock"
             android:layout_gravity="bottom"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center|bottom"
                tools:ignore="NestedWeights" >

                <ImageView
                    android:id="@+id/dial"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/dialer"
                    tools:ignore="ContentDescription" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/back"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/back" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal|center"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/sms"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:layout_gravity="center_horizontal|center"
                    android:src="@drawable/mms" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal|center"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/music"
                    android:layout_width="wrap_content"
                    android:layout_height="10dp"
                    android:src="@drawable/music"
                    android:visibility="gone" />
            </LinearLayout>
        </LinearLayout>





</LinearLayout>

我想把按钮放在这页的底部

我做错了什么

请让我知道

万分感谢


Chris

当您使用android:layout\u weight=“1”时,android:layout\u width或android:layou height的width应等于0dp。在您的情况下,第二个线性布局应该是android:layout_height=“0dp”

您可以使用RelativeLayout作为父级,然后使用alignParentBottom=“true”但是,我不完全确定您想要实现什么,即它应该是什么样子。

正如Hesam的回答所指出的那样,当您在第二个版面中使用
布局重量属性时,您应该设置
布局高度=0dp
…如果您使用的是Android Studio,那么它应该给您一个警告。然而,我想补充他的答案,在你的布局文件中有很多改进的空间…我的意思是很多!!!你有我称之为无用嵌套布局的意大利面条。举几个例子

  • 第二个
    LinearLayout
    完全没有用……它是空的,不需要
  • LinearLayout
    可以很容易地转换为
    RelativeLayout
    ,然后使用
    layout\u alignParentBottom=true将最底部的子视图推到底部,最后使用上面的
    layout\u将所有其他子视图堆叠在此底部视图的顶部
  • 你有很多嵌套的
    LinearLayout
    和一个孩子…我觉得这没用
  • 你有很多嵌套的
    RelativeLayout
    和一个孩子…我觉得这也没用
  • 我可以一直讲下去,但是你真的应该解决这些嵌套的布局问题,因为你给你的UI增加了很多不必要的开销……这是一个相当沉重的负担

    基于添加的屏幕截图的进一步建议 这就是我的建议

    • 我建议使用
      RelativeLayout
      作为根/顶布局
    • 添加一个
      列表视图
      以显示所有这些图像/图标,并使用
      layout\u height=wrap\u content设置
      layout\u alignParentTop=true
    • 然后在其下方添加一个水平方向的
      线性布局
      ,以显示按钮

    您可以使用RelativeLayout而不是LinearLayout作为根布局,然后将android:layout\u alignParentBottom=“true”设置为底部布局

    事实上,我更愿意说第二个布局绝对没有用#Leo完全解释道。如果您的LinearLayouts中没有任何内容,那么只需按照他解释的那样从代码中删除它们。如果我是你,我使用Relativelayout是基于Carsten和Leo所说的:“我正在开发一款ios风格的应用程序”,请立即停止工作,在你拥有“Android风格”之前拒绝继续。Android用户会因为你在商店里的iOS应用程序看起来很像而惩罚你……谢谢你的回复,我编辑了代码,但我仍然遇到同样的问题。你能看看新代码,看看我在做什么吗wrong@appd3vs抱歉,伙计,但我会投票结束这个问题…从技术上讲,你是在要求为你重新编写整个布局…这个疯狂,因为在你的布局中有太多的问题伙计们,谢谢你的回复,我编辑了代码,我仍然收到相同的问题。你能看看新代码,看看我做错了什么吗