android - 使用 ScrollView 时,RelativeLayout 按钮消失
问题描述
我的布局类似于本示例中使用的 on
唯一的区别是我想在 ScrollView 之后添加 3 个按钮。不幸的是,一旦我添加了 ScrollView,我的按钮就从屏幕上消失了。(当我有一个没有 ScrollView 的 TextView 时很好)。
我怎样才能让我的按钮回到屏幕底部?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/article_heading"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:textStyle="bold"
android:text="@string/article_title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/article_subheading"
android:layout_below="@id/article_heading"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:text="@string/article_subtitle"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/article_scrollview"
android:layout_below="@id/article_subheading">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="@dimen/line_spacing"
android:id="@+id/article"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:autoLink="web"
android:text="@string/article_text"/>
</ScrollView>
<Button
android:id="@+id/butConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/article_scrollview"
android:layout_marginStart="@dimen/button_margin"
android:onClick="onButLoginClicked"
android:text="@string/but_text_connect"/>
<Button
android:id="@+id/butAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/butConnect"
android:layout_marginStart="@dimen/button_margin"
android:text="@string/but_text_add" />
<Button
android:id="@+id/butSale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/butAdd"
android:layout_marginStart="@dimen/button_margin"
android:text="@string/but_text_sale" />
</RelativeLayout>
解决方案
仔细设计您的布局并遵循设计原则 遵循https://developer.android.com/design
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/article_heading"
android:background="@color/colorPrimary"
android:textColor="@android:color/white"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:textStyle="bold"
android:text="@string/article_title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/article_subheading"
android:layout_below="@id/article_heading"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:text="@string/article_subtitle"/>
<ScrollView
android:layout_above="@+id/butConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/article_scrollview"
android:layout_below="@id/article_subheading">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="@dimen/line_spacing"
android:id="@+id/article"
android:padding="@dimen/padding_regular"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:autoLink="web"
android:text="@string/article_text"/>
</ScrollView>
<Button
android:id="@+id/butConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/butAdd"
android:layout_marginStart="@dimen/button_margin"
android:onClick="onButLoginClicked"
android:text="@string/but_text_connect"/>
<Button
android:id="@+id/butAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/butSale"
android:layout_marginStart="@dimen/button_margin"
android:text="@string/but_text_add" />
<Button
android:id="@+id/butSale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="@dimen/button_margin"
android:text="@string/but_text_sale" />
</RelativeLayout>
推荐阅读
- python - PyTorch:提供的尺寸数量(0)必须大于或等于张量中的维度数量(1)
- javascript - 获取点击元素的索引
- python-3.x - TypeError 将带有 dtype int 的 Series 传递给 dateutil.relativedelta
- python - 如何获取通过 url 传递给 django 中的类 Create View 的值?
- amazon-web-services - JupyterHub 笔记本服务器返回 500 错误,Pod 卡在“终止”状态
- bash - 从 find 命令返回 True 或 False
- javascript - 在javascript中组合多个回调
- reactjs - 如何在使用 React.createContext 创建的 Mobx 商店之间进行通信
- arrays - Fortran 数组输入
- sql - Oracle sql - 我如何获得最新的值?