Высота AlertDialog - PullRequest
       25

Высота AlertDialog

0 голосов
/ 13 апреля 2011

Я пытаюсь показать 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" />

И что я получаю:

снимок экрана http://img546.imageshack.us/img546/2057/devicef.png

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

edit: заставить его работать со следующим 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>

Не лучшие решения, так как я получил бессмысленное вложение, но оно работает ...

Ответы [ 2 ]

0 голосов
/ 13 апреля 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">
0 голосов
/ 13 апреля 2011

Вы пытались использовать 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">
...