使用ScrollView时,RelativeLayout按钮消失

时间:2020-07-29 03:38:13

标签: android android-scrollview android-relativelayout

我的布局类似于此example

中使用的布局

enter image description here

唯一的区别是,我想在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>

1 个答案:

答案 0 :(得分:0)

仔细设计布局并遵循设计原则 跟随https://developer.android.com/design

@IBOutlet weak var label: UILabel!


@IBAction func onTap(_ sender: Any) {


}