2
votes

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.

2

2 Answers

3
votes

Change the ScrollView height to match_parent and set a white color as background. So something like this according to your code:

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

Note. The warning about the RelativeLayout can be easily explained. If you set it's height to wrap_content it'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.

1
votes

do like that

<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>