gpt4 book ai didi

Android 自定义对话框不会在大型设备中填充父项

转载 作者:太空狗 更新时间:2023-10-29 16:39:45 26 4
gpt4 key购买 nike

我有自定义对话框的布局,这适用于普通和小型设备,但在大型设备的情况下,它的宽度不适合宽度(填充父级),但我可以手动给它一些 dp 值来实现我想要的尺寸。我想知道为什么默认情况下 fill parent 不工作。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f70000"
android:gravity="center_horizontal"
android:orientation="vertical" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/textViewInvoice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceSmall" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<Button
android:id="@+id/buttonPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonPrint" />

<Button
android:id="@+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonCancel" />

</LinearLayout>

</LinearLayout>
</ScrollView>

</LinearLayout>

最佳答案

试试这个...

    Dialog dialog = new Dialog(YourActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = dialog.getWindow();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout lay = new RelativeLayout(YourActivity.this);
View dialogView = inflater.inflate(R.layout.your_dialog_layout,
lay);
dialog.setContentView(dialogView);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

关于Android 自定义对话框不会在大型设备中填充父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19994404/

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