views:

278

answers:

1

Hi,

I cannot get my relative layuot view to shrink when using it in the follwing layout, used as a dialog. In below example the scrollview always expands to fill the entire dialog which looks very ugly if there is not much actual content.

I have tried most combinations of fill_parent, wrap_content etc without success.

The problem seems to be that setting the button to "align_bottom" will cause the dialog to fill its height. But if I change the order and have to button placed below the scrollview the button will not be visible if a lot of content is shown...

Workaround (that I think is a very ugly solution) is to set a margin-bottom on the scrollview and then the same negative margin-top on the button. But I'm not sure how this will look at different displays.

Please help /Rudas

<RelativeLayout android:id="@+id/RelativeLayout01" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content">

<ScrollView android:id="@+id/ScrollView01" android:layout_above="@+id/dialogCloseButton" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/dialogContent" android:orientation="vertical" android:paddingBottom="10dp">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</ScrollView>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Close" android:id="@+id/dialogCloseButton" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"></Button>
</RelativeLayout>
A: 

ScrollView is special type of FrameLayout. This means it will always start at top left corner of parent layout. Effect is overlapping other views and the RelativeLayout settings will have no effect. Solution is to put StrollView in separate layout (for instance LinearLayout).

MatejC