1

I've a problem with dialog display dimension. With following code i make my custom dialog with ScrollView inside, but when it shown, ScrollView fit dialog dimension, but the inside linear layout has some controls out of scrollable area. I can't understand why and how to resolve.

Into phone with little display it's a problem because some controls are unreachable.

Dialog creation:

AlertDialog.Builder alert = new AlertDialog.Builder(DataMainPage.this);                     
startNewTestSessionDialog = new  StartTestDialog(DataMainPage.this);
                     alert.setView(startNewTestSessionDialog);
alert.setPositiveButton("Start", new DialogInterface.OnClickListener() {<...>});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {<..>});

Dialog d = alert.create();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
d.show();
d.getWindow().setAttributes(lp);

Dialog view xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sample="http://schemas.android.com/apk/res/ips.tecnos.saildata"
android:id="@+id/startTest_dialogView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="65dp"
android:fillViewport="true" >

<LinearLayout
    android:id="@+id/startTest_viewContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:clipToPadding="false"
    android:orientation="vertical" >

    <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
     android:orientation="horizontal"
     android:weightSum="2"
     android:layout_marginBottom="5dp" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:layout_marginRight="7dp" 
            android:gravity="right|center_vertical"
            android:text="@string/testStart_disableWind"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <CheckBox
            android:id="@+id/startTest_disableWind"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:text="" />

    </LinearLayout>

     <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:layout_marginTop="10dp"
            android:text="@string/testStart_boatType"
            android:textAppearance="?android:attr/textAppearanceMedium" />

      <LinearLayout 
         android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_marginBottom="5dp" >

        <Spinner
            android:id="@+id/startTest_boatSelect"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center|right"
            android:layout_weight="2"
            android:gravity="center|right" />

        <Button
            android:id="@+id/startTest_modifyBoatPolar"
            android:layout_width="0dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="@string/testStart_modboatPolar" />

    </LinearLayout>

   <...other controls with same logic...>

</LinearLayout>

</ScrollView>

Screenshoot (Nexus5): ScrollView is at its end, and as you can see button and hidden spinner is out of scrollView border. Screnshoot

ruscoff
  • 11
  • 1
  • 3
  • I didn't understand your problem, you can't reach the "other controls" when you scroll? Can you post some screenshots? – Rami Apr 12 '15 at 11:35
  • Add view like given [Here](http://stackoverflow.com/questions/2795300/how-to-implement-a-custom-alertdialog-view) in second answer – Harin Apr 13 '15 at 09:20
  • I'll try and let you know. Thanks. i'll post also an screenshoot! ;) – ruscoff Apr 13 '15 at 20:40
  • I try with Harry link but it doesn't work, android.R.id.body not exist anymore. Google alert reference dialog says that it is valid only for subclass of dialog. – ruscoff Apr 13 '15 at 22:14

1 Answers1

0

With some casual changes i found solution!

The problem was property of ScrollView:

android:layout_gravity="center"

removing it, the layout is right positioned.

ruscoff
  • 11
  • 1
  • 3