滚动视图下方的固定按钮未显示

时间:2018-01-07 10:26:52

标签: java android

我想创建一个包含我以编程方式添加的项目的滚动视图,并在底部创建一个固定按钮。但是使用下面的代码,我看不到任何按钮。

代码:

<LinearLayout
    android:id="@+id/list_warrantys"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <LinearLayout
            android:id="@+id/show_warratys"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </LinearLayout>
    </ScrollView>
    <Button
        android:id="@+id/add_warranty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/mybutton"
        android:text="@string/add_button"
        android:layout_marginBottom="5dp"/>
</LinearLayout>

Pciture of screen

1 个答案:

答案 0 :(得分:1)

<RelativeLayout android:id="@+id/list_warrantys"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<ScrollView
    android:layout_above="@+id/add_warranty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <LinearLayout
        android:id="@+id/show_warratys"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </LinearLayout>
</ScrollView>
<Button
    android:id="@+id/add_warranty"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/mybutton"
    android:text="@string/add_button"
    android:layout_marginBottom="5dp"/>

以root身份使用RelativeLayout并将android:layout_alignParentBottom="true"设置为您的按钮,将android:layout_above="@+id/add_warranty"设置为ScrollView