Android user dialog with scrollview buttons pops screen

I have a custom dialog with a layout like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/mylayout"> <LinearLayout android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView ... /> <TextView .../> </LinearLayout> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/title"> <LinearLayout ...> <TextView ... android:text="lots of text........" /> <TextView .../> </LinearLayout> </ScrollView <RelativeLayout ... android:layout_below="@+id/scrollView"> <Button ...> <Button ...> </RelativeLayout> </RelativeLayout> 

My problem is that scrollview is that with too much text in scrollview, the buttons at the bottom are pushed out of the dialog box. I was able to prevent this by binding a RelativeLayout, which contains the buttons at the bottom, using android: layout_alignParentBottom = "true", but I stretch the entire dialog at the bottom of the screen when there is less text in scrollview and I don't want this.

How can I get such a layout:

 [SOME TEXT] [Scrollable region] [Buttons] 
+7
source share
2 answers

Try LinearLayout instead of RelativeLayout Put the buttons in a separate layout and put the weight on the button layout.

 LinearLayout - top level start, android:layout_weight="0" LinearLayout with TextViews embeded, android:layout_weight="1" LinearLayout with ScrollView embeded, android:layout_weight="1" LinearLayout with Buttons embeded, android:layout_weight="1" LinearLayout - top level finish, android:layout_weight="0" 
+6
source

Despite the fact that the question is old, here is what helped in my case. Hope this can help others, as it took me a while to go downstairs.

 alertDialogBuilder.setMessage(null); 
+1
source

All Articles