I have a dialog with this content:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginBottom="25dp" >
<LinearLayout
...
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/closebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/scrollview"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I want the dialog to be sized vertically to fit as much of the content of the LinearLayout as it can. However, I’m finding that, if the contents of the LinearLayout are too tall, the ScrollView fills the dialog and the close button gets pushed past the bottom and is not visible.
One thing I tried was to make the Button layout_alignParentBottom=”true” and make the ScrollView layout_above=”@+id/closebtn”, but then the dialog always stretches to fill the whole screen vertically, even if the content of the LinearLayout is really short.
I ended up changing my RelativeLayout to a LinearLayout to get this working. I didn’t do that originally because when I tried it it gave my a really tall and skinny dialog (the inner LinearLayout contains ImageViews and TextViews). But, surprisingly, changing all my views from width=fill_parent to wrap_content caused the dialog to stretch horizontally to fill the screen, which is what I wanted, and the height behaves correctly.