Высота AlertDialog

Я пытаюсь показать AlertDialog со следующим кодом:

final int requestLayout = R.layout.triprunning_pause;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(requestLayout, null);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.runningTrip_pause_title);
    builder.setIcon(android.R.drawable.ic_media_pause);
    builder.setView(layout);

    dialog = builder.create();
    dialog.show();

XML, который я покажу, выглядит так:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/triprunning_pause_root">

<TextView android:id="@+id/questionText" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:text="@string/runningTrip_pause_text"
    android:textSize="22sp" android:gravity="center_vertical|center_horizontal"
    android:paddingBottom="5dp" />

<View android:id="@+id/buttons_helper" android:layout_width="0dp"
    android:layout_height="0dp" android:layout_centerHorizontal="true" />

<Button android:id="@+id/continueButton" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:text="Fortsetzen"
    android:layout_below="@id/questionText" android:layout_toLeftOf="@id/buttons_helper" />

<Button android:id="@+id/stopButton" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:text="Beenden"
    android:layout_below="@id/questionText" android:layout_toRightOf="@id/buttons_helper" />

And what I get is:

скриншот http://img546.imageshack.us/img546/2057/devicef.png

Никак не могу понять, почему после кнопок буксировки это черное пространство? Есть идеи?

изменить: заставить его работать со следующим XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/triprunning_pause_root" android:orientation="vertical">

<TextView android:id="@+id/questionText" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:text="@string/runningTrip_pause_text"
    android:textSize="22sp" android:gravity="center_vertical|center_horizontal"
    android:paddingBottom="5dp" />

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button android:id="@+id/continueButton" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="Fortsetzen"
        android:layout_below="@id/questionText" android:layout_toLeftOf="@id/buttons_helper"
        android:layout_weight="1" />

    <Button android:id="@+id/stopButton" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="Beenden"
        android:layout_below="@id/questionText" android:layout_toRightOf="@id/buttons_helper"
        android:layout_weight="1" />
</LinearLayout>

Not the best solutions as i got a senseless nesting but it works...


person Stefan    schedule 13.04.2011    source источник


Ответы (2)


Вы пытались использовать android:layout_height="wrap_content" для своего относительного макета?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/triprunning_pause_root">
person Tima    schedule 13.04.2011
comment
Хмммм... а что если попробовать использовать LinearLayout? - person Tima; 13.04.2011
comment
Или лучше. Почему вы используете DialogBuilder, а не Dialog? В примере Google они используют Dialog developer.android.com/guide/ topics/ui/dialogs.html#CustomDialog - person Tima; 13.04.2011
comment
Была такая же проблема с использованием Dialog-Class! Я нашел решение с помощью LinearLayout... написал его в свой первый пост. Спасибо! - person Stefan; 13.04.2011
comment
Хорошо :) не забудьте удалить относительные позиции (например, android:layout_toRightOf и т. д.), они вам не нужны в вашем LinearLayout - person Tima; 13.04.2011

Я использую LinearLayout, чтобы получить нужный вам диалог.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/triprunning_pause_root">
person Brandon    schedule 13.04.2011