2011-04-13 45 views
0

我试图表明一个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" /> 

而我得到的是:

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

还不如我得到了一个毫无意义的嵌套,但它的工作原理的最佳解决方案......

回答

0

您是否尝试过为相对布局使用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"> 
+0

是的..以前试过..相同的结果! – Stefan 2011-04-13 11:42:17

+0

嗯......如果您尝试使用LinearLayout,该怎么办? – Tima 2011-04-13 11:46:40

+0

或更好。为什么使用DialogBu​​ilder而不是Dialog?在谷歌的例子中,他们使用的是Dialog http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog – Tima 2011-04-13 11:50:14

0

我使用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">