gpt4 book ai didi

Android Alertdialog 在模拟器和设备上的大小不同

转载 作者:行者123 更新时间:2023-11-30 03:55:36 25 4
gpt4 key购买 nike

我创建并显示了一个 Alertdialog,它在模拟器中看起来不错,但在我的设备中看起来很奇怪。

这是它在模拟器中的样子:

enter image description here

这是它在设备中的样子:

enter image description here

这是我正在执行以显示对话框的代码:

    AlertDialog.Builder builder;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact));
tbMissatge = (EditText) layout.findViewById(R.id.ppc_tbMissatge);
builder = new AlertDialog.Builder(this);


builder.setView(layout);
ppEnviarMsg = builder.create();


btEnviar = (Button) layout.findViewById(R.id.ppc_btEnviar);
btEnviar.setOnClickListener(this);

ppEnviarMsg.show();


ppEnviarMsg.getWindow().getAttributes().gravity = Gravity.CENTER;

这里是弹出窗口的布局:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ppc_llContact"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#414145"
android:orientation="vertical"
android:gravity="center">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="@string/ppc_lbContact"
android:layout_margin="4dp"/>

<EditText
android:id="@+id/ppc_tbMissatge"
android:hint="@string/ppc_tooltipContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:inputType="textMultiLine"
android:gravity="top"
android:lines="5">
</EditText>

<Button android:id="@+id/ppc_btEnviar"
android:text="@string/ppc_btEnviar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginTop="10dp"/>

</LinearLayout>

会不会跟Sense有关?我的设备是 HTC Desrie S,运行 ICS 和 Sense。有人知道吗?

感谢您的帮助!

最佳答案

我觉得问题可能出在这里:

View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact));

您将 Activity 的某些布局 ppc_llContact 用作“为返回的层次结构的根提供一组 LayoutParams 值的对象”,这是毫无意义的,因为此布局不会参与在对话框的最终层次结构中。

改用这个:

View layout = inflater.inflate(R.layout.popup_contact, null);

另一种选择是以这种方式强制设置对话框的大小:

ppEnviarMsg.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
//FILL_PARENT is an example

关于Android Alertdialog 在模拟器和设备上的大小不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13414987/

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