将 LinearLayout 保持在屏幕底部 [英] Keep LinearLayout at the bottom of screen

查看:69
本文介绍了将 LinearLayout 保持在屏幕底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题被问了很多,因为我尝试了很多在这里发布的例子,但我无法让它工作,这就是我所拥有的:

I know this question is asked a lot, because I was trying a lot of examples posted in here, but I just Can't make it work, this is what I have:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:background="#3F51B5"
    android:padding="5dp"
    android:paddingBottom="500dp">
    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/linearLayout2"
        android:gravity="bottom"
        android:layout_weight="1">
        <Button
            android:text="Button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnTarjeta"
            android:background="@color/my_purple"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="20dp" />
        <TextView
            android:text="Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/my_white"
            android:id="@+id/textView1"
            android:fontFamily="sans-serif-medium"
            android:layout_marginBottom="10dp" />
        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/radioGp"
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_marginBottom="10dp" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout3"
        android:layout_gravity="bottom">
        <Button
            android:text="Button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button2" />
        <Button
            android:text="Button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button1" />
    </LinearLayout>
</LinearLayout>

可能是问题"的一件事是我正在动态填充单选组内的单选按钮,所以有时可以是 4 个单选按钮,而在其他时刻可以是 1,我不知道如果这会影响我正在尝试做的任何事情.

One of the things that might be a "problem" is that I'm dynamically filling the radio buttons inside the radio group, so sometimes can be 4 radio buttons and in an other moment can be 1, I don't know if this affect any of what I'm trying to do.

我想要做的是将第一个线性层保留在顶部,将第二个线性层保留在按钮处.我做错了什么?

And what I'm trying to do is keep the the first linear layer at the top, and the second linear layer at button. What I'm doing wrong?

推荐答案

请下次更好地描述您到底想要什么.我不确定,但也许你想要这个.将您的根 LinearLayout height 更改为 match_parent,并删除第一个 LinearLayout android:gravity="bottom"

Please, next time provide better description of what you exactly want. I'm not sure, but maybe you want this. Change your root LinearLayout height to match_parent, and remove first LinearLayout android:gravity="bottom"

Android Studio 预览版截图

这篇关于将 LinearLayout 保持在屏幕底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆