0

I try to show an AlertDialog with the following code:

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

The XML I'll show looks like:

<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:

screenshot http://img546.imageshack.us/img546/2057/devicef.png

I can not really figure out, why there is this black space after the tow buttons? Any idea?

edit: get it to work with the following 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...

Geore Shg
  • 1,299
  • 5
  • 23
  • 38
Stefan
  • 1,007
  • 1
  • 11
  • 32

2 Answers2

0

Have you tried to use android:layout_height="wrap_content" for your relative layout?

<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">
Tima
  • 12,765
  • 23
  • 82
  • 125
  • Hmmmm ... what if you try to use LinearLayout? – Tima Apr 13 '11 at 11:46
  • Or better. Why do you use DialogBuilder and not the Dialog? In example of google they are using Dialog http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog – Tima Apr 13 '11 at 11:50
  • Had the same problem using the Dialog-Class! I found a Solution using the LinearLayout... wrote it to my first post. Thx! – Stefan Apr 13 '11 at 12:12
  • Nice :) don't forget to remove relative positions (i.e. android:layout_toRightOf etc.), you don't need them in your LinearLayout – Tima Apr 13 '11 at 12:55
0

I use a LinearLayout to get the dialog you're going for.

<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">
Brandon
  • 2,900
  • 1
  • 23
  • 36