首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android线性布局-如何将元素保留在视图底部?

Android线性布局-如何将元素保留在视图底部?
EN

Stack Overflow用户
提问于 2011-03-25 04:50:08
回答 6查看 125.6K关注 0票数 76

我有一个TextView,我想将它固定在一个使用垂直排列元素的LinearLayout的景观活动的底部。

我已经在文本视图上设置了android:gravity="bottom",但它仍然希望恰好位于LinearLayout的最后一个元素之下,这正是我不希望它做的事情。

有什么建议吗?

EN

回答 6

Stack Overflow用户

发布于 2011-03-25 04:54:03

您必须展开上面的一个视图,通过在其上设置android:layout_weight="1"来填充剩余空间。这将把您的最后一个视图推到底部。

以下是我的意思的简要概述:

代码语言:javascript
复制
<LinearLayout android:orientation="vertical">
    <View/>
    <View android:layout_weight="1"/>
    <View/>
    <View android:id="@+id/bottom"/>
</LinearLayout>

其中每个子视图的高度都是"wrap_content",其他的都是"fill_parent"

票数 122
EN

Stack Overflow用户

发布于 2014-10-01 19:53:53

我认为这将是一个完美的解决方案:

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Other views -->
    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <!-- Target view below -->
    <View
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

</LinearLayout>
票数 60
EN

Stack Overflow用户

发布于 2014-09-24 13:36:21

步骤1:在线性布局中创建两个视图

步骤2: First view必须设置为android:layout_weight="1“

第三步:自动向下推送第二个视图

代码语言:javascript
复制
<LinearLayout
android:id="@+id/botton_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <View
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

    <Button
    android:id="@+id/btn_health_advice"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


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

https://stackoverflow.com/questions/5425341

复制
相关文章

相似问题

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