开发者

Height of an AlertDialog

I try to show an AlertDialog with the following code:

fin开发者_运维知识库al 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...


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


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">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜