Android не имеет достаточно большого размера Custom Dialog - PullRequest
4 голосов
/ 27 сентября 2010

Я использую пользовательский диалог, который содержит текстовое поле, изображение и кнопку.Текст может содержать HTML.Иногда нижняя часть диалога отсекается от нижней части, когда текст достаточно длинный.Как я могу предотвратить это?Я хочу, чтобы Android определял размер диалога, но, похоже, он этого не делает.Нужно ли мне в этом случае самостоятельно настраивать размер Диалога?

Вот макет ...

<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's 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>

А вот код, который я использую для его загрузки ...

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;

И вот несколько слов о том, что я имею в виду ..

alt text

Спасибо,

Джон

Ответы [ 2 ]

1 голос
/ 08 ноября 2011

Это не идеально, но я исправил это, установив компоновку диалога относительно отображения по умолчанию.

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);

Просто настройте значения ".90", пока не почувствуете, что все правильно.*

0 голосов
/ 12 октября 2012

Вот решение:

  1. Вы должны добавить Linearlayout вне xml-файла вашего диалога
  2. Затем установите гравитацию этого Linearlayout как "центр"
  3. последний шаг - создание LayoutParams и установка его в диалог

    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 (ПОЛ).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...