我有以下简单的布局

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/answerMainFrame"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/background"
        android:isScrollContainer="true"
        android:onClick="toAnswer" >

        <ImageView
            android:id="@+id/answer_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:contentDescription="@string/question_img_cd" />

        <TextView
            android:id="@+id/answer"
            style="@style/Question"
            android:layout_below="@id/answer_img" />
    </RelativeLayout>

</ScrollView>

但有时,根据imageview和textview的大小,它不会填充屏幕的高度。没关系。我只希望屏幕的其余部分是白色而不是黑色。
我试过将白色的android:background="@color/background"设置为scrollview,但是我得到了相同的结果。
我也尝试过将android:layout_height="wrap_content"设置为relativeLayout,但它显示了一个警告。
我该怎么办?
谢谢。

最佳答案

ScrollView高度更改为match_parent并将白色设置为背景。所以根据你的代码如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="match_parent"
                  android:background="@color/background">
...

注意。
关于RelativeLayout的警告很容易解释。如果将其高度设置为wrap_content则无法执行此操作,因为其内部的元素需要一组固定的维度,以便其父元素能够执行诸如附加到底部、中心或其他操作。
一开始我也有些困惑。

07-28 01:49
查看更多