Android doesn't customize user dialog big enough

I use a custom dialog that contains a text box, image and button. The text may contain HTML. Sometimes the bottom of the dialog comes off below when the text is long enough. How can I prevent this? I want Android to determine the size of the dialog box, but that doesn't seem to be the case. Do I have to determine the Dialog myself in this case?

Here is the layout ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/alert_root_incorrect" style="@style/AlertDialogTheme" android:background="@drawable/rounded_alert" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/rounded_alert" > <TableLayout android:stretchColumns="0" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableRow> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:textStyle="bold" android:text="Sorry, that wrong!" android:textColor="@color/gray_dark" /> <ImageView android:id="@+id/check" android:background="@drawable/xmark" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginRight="10dp" /> </TableRow> </TableLayout> <TextView android:id="@+id/alert_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ellipsize="none" android:text="In fact, this is where the explanation will go. Something about how this passage related to the topic" android:textColor="#000000" /> <Button android:id="@+id/okay_button" android:layout_width="100dp" android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="center_horizontal" android:background="@drawable/rounded_alert_button" android:text="Okay" android:textColor="@color/white" android:textSize="20sp" /> </LinearLayout> </LinearLayout> 

And here is the code that I use to download it ...

 if ( null == layout ) { this.layout = inflater.inflate(R.layout.alert_incorrect, (ViewGroup) findViewById(R.id.alert_root_incorrect)); } TextView message = (TextView) layout.findViewById(R.id.alert_text); message.setText(Html.fromHtml(card.getConclusion())); ((Button) layout.findViewById(R.id.okay_button)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dismissDialog(INCORRECT_DIALOG); nextQuestion(); } }); layout.requestLayout(); dialog = new Dialog(this, R.style.AlertDialogTheme); dialog.setContentView(layout); dialog.setCancelable(false); return dialog; 

And here is a grasp of what I mean.

alt text

Thanks,

John

+4
source share
2 answers

This is not ideal, but I fixed it by setting the layout of the dialog box relative to the default display.

 dialog = new Dialog(this, R.style.AlertDialogTheme); dialog.setContentView(layout); Window window = dialog.getWindow(); window.setLayout( (int)(window.getWindowManager().getDefaultDisplay().getWidth() * .90), (int)(window.getWindowManager().getDefaultDisplay().getHeight() * .90 )); dialog.setCancelable(false); 

Just adjust the β€œ.90” values ​​until they feel right.

+1
source

Here is the solution:

  • You should add Linringayout outside your dialog xml file.
  • Then set this Linringayout power to β€œcenter”
  • The final step is to create LayoutParams and set it in the dialog box.

    android.view.WindowManager.LayoutParams lp = new android.view.WindowManager.LayoutParams (); lp.width = android.view.WindowManager.LayoutParams.FILL_PARENT; lp.height = android.view.WindowManager.LayoutParams.FILL_PARENT; alertDialog.getWindow () SetAttributes (LP) ;.

0
source

All Articles