如何解决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\" />
我得到的是:
屏幕截图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>
不是最好的解决方案,因为我没有意义的嵌套,但是它可以工作...
解决方法
您是否尝试过将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\">
,我使用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\">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。