首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >layout_gravity底部不工作

layout_gravity底部不工作
EN

Stack Overflow用户
提问于 2015-02-04 07:39:32
回答 2查看 670关注 0票数 0

我使用以下XML绘制带有标题、子标题、图像和按钮的布局。图像占用了所有剩余的空间,但在最后,我将其设置为visibility = View.GONE,并且我的按钮没有对齐到底部。我做错了什么?

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:baselineAligned="false">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/kasel"
        android:id="@+id/txtChokeNext"
        android:textSize="20sp"
        android:gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_gravity="top"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/kaselDesc"
        android:id="@+id/txtChokeNextDesc"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:layout_gravity="top"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/imgChokeDesc"
        android:src="@drawable/kasel"
        android:adjustViewBounds="true"
        android:baselineAlignBottom="false"
        android:cropToPadding="false"
        android:layout_weight="1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/firstAidNext"
        android:id="@+id/buttonChokeNext"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="20dp"
        android:paddingRight="10dp"
        android:paddingBottom="20dp"
        android:layout_gravity="bottom"
        />

</LinearLayout>

前谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-04 07:48:15

您可以将布局更改为RelativeLayout,并将此参数设置为Button:

代码语言:javascript
复制
android:layout_alignParentBottom="true"

您还应该在子标头和图像中添加android:layout_below="...",以便一个接一个地放置它们(替换.使用应该在您正在编辑的元素之上的元素的id )

票数 1
EN

Stack Overflow用户

发布于 2015-02-04 07:45:28

解决你的问题

代码语言:javascript
复制
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/kasel"
            android:id="@+id/txtChokeNext"
            android:textSize="20sp"
            android:gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:layout_gravity="top" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/kaselDesc"
            android:id="@+id/txtChokeNextDesc"
            android:gravity="center"
            android:layout_marginTop="10dp"
            android:textStyle="bold"
            android:layout_gravity="top" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/imgChokeDesc"
            android:src="@drawable/kasel"
            android:adjustViewBounds="true"
            android:baselineAlignBottom="false"
            android:cropToPadding="false"
            android:layout_weight="1" />
    </LinearLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/firstAidNext"
        android:id="@+id/buttonChokeNext"
        android:layout_marginTop="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="20dp"
        android:paddingRight="10dp"
        android:paddingBottom="20dp"
        android:layout_gravity="bottom" />

</LinearLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28315950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档