Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android custom dialog with scrollview pushes buttons off the screen

Tags:

android

layout

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 the scrollview is that when there is too much text in the scrollview, the buttons below are pushed down out of the dialog. I've been able to prevent it by anchoring the RelativeLayout that contains the buttons to the bottom using android:layout_alignParentBottom="true", but I that stretches the entire dialog to the bottom of the screen when there is less text in the scrollview and I don't want that.

How can I get a layout like this:

[SOME TEXT]
[Scrollable region]
[Buttons]
like image 502
Charles Ma Avatar asked Dec 04 '12 20:12

Charles Ma


2 Answers

Try LinearLayout instead of the RelativeLayout Put the buttons in a separate layout and put a weight on the buttons 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"
like image 105
Gligor Avatar answered Nov 15 '22 17:11

Gligor


Even though the question is kind of old here is what helped in my case. Hope this may help others as it took me quite a while to down trace.

alertDialogBuilder.setMessage(null);
like image 34
HeyMan Avatar answered Nov 15 '22 18:11

HeyMan