I have the following simple layout
<?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>
but sometimes, depending on the size of the ImageView and TextView, it doesn’t fill the height of the screen. That’s ok. I just want the rest of the screen to be white instead of black.
I’ve tried setting android:background="@color/background", which is white, to the ScrollView but I get the same.
I’ve also tried setting android:layout_height="wrap_content" to the Relativelayout but it shows a warning.
What should I do?
Thanks.
Change the
ScrollViewheight tomatch_parentand set a white color as background. So something like this according to your code:Note.
The warning about the
RelativeLayoutcan be easily explained. If you set it’s height towrap_contentit’s unable to do so because the elements its holding inside require a fixed set of dimensions for its parent to be able to do things such as attach to the bottom, or center or whatever.I also had some confusion around this at first.