我有以下简单的布局
<?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,但它会显示警告。
我该怎么办?
感谢。
答案 0 :(得分:3)
将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
,则它无法这样做,因为其内部的元素需要一组固定的维度,以便其父级可以执行诸如附加到底部或中心或其他任何内容的操作。
起初我也对此感到困惑。
答案 1 :(得分:1)
喜欢那样
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff >
<RelativeLayout
android:id="@+id/answerMainFrame"
android:layout_width="wrap_content"
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>