gpt4 book ai didi

android - 如何设置 Android Dialog 的 MaxWidth?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:12 25 4
gpt4 key购买 nike

我有一个带有自定义样式的对话框,该样式使用我在 XML 文件中定义的布局。我希望此对话框在纵向模式下填满屏幕宽度,但在横向模式下仅约 400dip。 MaxWidth 似乎是实现此目的的完美方式,但我不知道如何将 MaxWidth 分配给对话框样式或 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.xmllayout-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 布局。

附言我使用 LinearLayout 只是为了举例。任何布局 View 都可以。

关于android - 如何设置 Android Dialog 的 MaxWidth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6143179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com