我有一个使用我在XML文件中定义的布局的自定义样式的对话框。我希望这个对话框以纵向模式填充屏幕的宽度,但只有横向模式下的大约400dip。 MaxWidth似乎是完美的方式,但我不知道如何将MaxWidth分配给对话框样式或XML布局。如何设置Android对话框的MaxWidth?
回答
你试过设置android:minWidth
和android:minHeight
在您的自定义XML
假设你使用一个叫做layout/dialog_core.xml
未来布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
//All your dialog views go here....
</LinearLayout>
然后,您可以创建两个文件:layout/dialog.xml
和layout-land/dialog.xml
。
的layout/dialog.xml
文件不会限制宽度:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<include layout="@layout.dialog_core.xml" />
</LinearLayout>
当你layout-land/dialog.xml
应该有宽度的限制:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:maxWidth="400dp" >
<include layout="@layout.dialog_core.xml" />
</LinearLayout>
当然,你现在需要在代码中使用R.layout.dialog
布局。
P.S.我仅以举例的目的使用LinearLayout
。任何布局视图都可以。
我试过了,但android:maxWidth没有出现在LinearLayout的自动完成提议窗口中,所以我认为我不能使用它。无论如何,我尝试着把它放到项目中,但是这个属性没有效果,对话框仍然延伸到屏幕上。 – chefgon 2011-05-26 18:52:20
@chefgon'android:maxWidth'不是你正在寻找的。你想要的是在纵向模式下android:layout_width =“fill_parent”。按照inazaruk的说法,不要忘记将'dialog-land.xml'放在布局文件夹'res/layout-land'中。 Android将根据屏幕方向自动加载正确的布局('dialog.xml'或'dialog-land.xml')。 – 2011-07-07 20:03:09
据我所知,根据开发文档,'dialog-land.xml'也应该命名为'dialog.xml',但放置在@ resur说的'res/layout-land'中 - 我相信@inazaruk在他的解释中对他们进行了不同的命名。 – ataulm 2012-04-08 18:36:57
你可以在这里找到一个实际的解决方案:setting a max width for my dialog
答案是使用对话的主题活动,但考虑到它是基于Window对象,它应该不会太复杂,以适应它的对话框。
- 1. 如何设置对话框的位置?
- 2. Tooltipster maxWidth设置
- 3. 设置Android对话框位置
- 4. 如何设置对话框的宽度?
- 5. 如何设置对话框的宽度
- 6. 如何使用对话框片段设置全屏对话框
- 7. 如何在对话框中设置Butto.onClickListener?
- 8. 如何设置Feed对话框
- 9. 如何设置全宽对话框?
- 10. 如何设置搜索对话框的文本 - Android
- 11. 如何从edittext android中设置Datepicker对话框中的日期?
- 12. 里面的Android对话框,如何设置onActivityResult for startActivityForResult?
- 13. 如何动态设置Xamarin Android对话框活动的标题?
- 14. android如何设置进度对话框的时间
- 15. 如何在Android中设置对话框的图标
- 16. 如何在对话框中设置ListView的“onItemSelectedListener”。 Android
- 17. 用于设置应用程序的Android对话框设置
- 18. 如何在对话框中设置videoView android
- 19. 如何在Android中设置登录对话框?
- 20. 如何在android自定义对话框中设置listviewadapter?
- 21. Android -alert对话框设计
- 22. 如何设置意图在沃森对话对话框
- 23. 重置Android对话框
- 24. maxWidth uncenters对话框(模态)的材料 - 我
- 25. 如何设置jqgrid的错误对话框的位置?
- 26. 自定义微调器对话框:对话框的popupbackground设置
- 27. 在android中设置自定义对话框的位置?
- 28. 如何在Android中显示对话框中的对话框?
- 29. Android:如何将对象从对话框传递到对话框
- 30. 如何设置代码中的对话框文本位置?
不,但我不明白minWidth和minHeight如何帮助我设置最大宽度。 – chefgon 2011-05-27 16:16:15