user940016
user940016

Reputation: 2938

View background color ignored

I have this (part of a) layout:

<ScrollView android:layout_width="0dip" android:layout_height="fill_parent"
    android:layout_weight="0.8">
    <HorizontalScrollView android:id="@+id/paint_board_container" 
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <View android:layout_width="wrap_content" android:layout_height="fill_parent"
            android:background="@android:color/white"/>
    </HorizontalScrollView>
</ScrollView>

The background color of the innermost view is set to white, but I can't see it on the screen, even if its layout width is also set to fill_parent. Where is the problem? Thanks.

Updated layout:

<ScrollView android:layout_width="0dip" android:layout_height="fill_parent"
    android:layout_weight="0.8" android:fillViewport="true" 
    android:background="#00FF00">
    <HorizontalScrollView android:id="@+id/paint_board_container" 
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:fillViewport="true"
        android:background="#FF0000">
        <View android:layout_width="2000dip" android:layout_height="1000dip"
            android:background="@android:color/white"/>
            <!-- android:minWidth="100dip" android:minHeight="100dip"/> -->
    </HorizontalScrollView>
</ScrollView>

Now I see the vertical scroll view, but not the horizontal one, even though the innermost view's width is set to 2000dip. How do I make the horizontal scroll view show?

Upvotes: 0

Views: 588

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

A View by default has width and height of 0. Since the HorizontalScrollView has a height of wrap_content, it will set its height to 0 as well. Give the inner view a non-zero minimum width and height and you should see some white on the screen.

Upvotes: 2

Related Questions