一个AlertDialog高度 [英] Height of an AlertDialog

查看:156
本文介绍了一个AlertDialog高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图表明一个AlertDialog具有以下code:

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

我会告诉看起来像XML:

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

而我得到的是:

我真的不能弄清楚,为什么会出现拖按钮后,这个黑色的空间吗?任何想法?

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

编辑:得到它与下面的XML工作:

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

推荐答案

您是否尝试过使用Android:layout_height =WRAP_CONTENT为您相对布局

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

这篇关于一个AlertDialog高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆