android – Popup(使用PopupWindow或Dialog)填充屏幕的宽度没有明显的原因

android – Popup(使用PopupWindow或Dialog)填充屏幕的宽度没有明显的原因,第1张

概述我想要d出一个表现! =) 问题是d出窗口“填充整个屏幕宽度”,即使布局清楚地表明它应该“wrap_content”.如果我使用Dialog或PopupWindow无关紧要. 首先,d出窗口的XML布局,popup_message.xml: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://sch 我想要d出一个表现! =)

问题是d出窗口“填充整个屏幕的宽度”,即使布局清楚地表明它应该“wrap_content”.如果我使用Dialog或PopupWindow无关紧要.

首先,d出窗口的XML布局,popup_message.xml:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="match_parent"    androID:layout_margin="20dp"    androID:background="@androID:color/transparent"    androID:orIEntation="vertical" >    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="40dp"        androID:orIEntation="horizontal"        androID:layout_gravity="center" >        <TextVIEw            androID:layout_wIDth="match_parent"            androID:layout_height="fill_parent"            androID:layout_gravity="center"            androID:background="@androID:color/transparent"            androID:gravity="center_vertical|center_horizontal"            androID:orIEntation="horizontal"            androID:paddingleft="10dp"            androID:text="@string/new_message"            androID:textcolor="#000000"            androID:textAllCaps="true" >        </TextVIEw>    </linearLayout>    <relativeLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:padding="15dp"        androID:background="#ffffff"        androID:gravity="center_horizontal"        androID:orIEntation="vertical" >        <TextVIEw            androID:ID="@+ID/popup_message_textVIEw"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:textAppearance="?androID:attr/textAppearanceMedium"            androID:textCursorDrawable="@null" >        </TextVIEw>        <button            androID:ID="@+ID/jobvIEw_pickup_start_submit"            androID:layout_wIDth="fill_parent"            androID:layout_height="35dp"            androID:layout_below="@+ID/popup_message_textVIEw"            androID:layout_gravity="center_vertical|center_horizontal"            androID:layout_marginBottom="15dp"            androID:layout_margintop="15dp"            androID:gravity="center_horizontal"            androID:text="Confirm"            androID:textcolor="#000000" />    </relativeLayout></linearLayout>

我正在使用的代码:

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);VIEw input = inflater.inflate(R.layout.popup_message,null);PopupWindow pw = new PopupWindow(input,LayoutParams.WRAP_CONTENT,true);VIEw v = findVIEwByID(R.ID.main_deviceInfobar);pw.showAtLocation(v,Gravity.CENTER,0);

我也试过这个:

Dialog dialogManualStart = new Dialog(MainActivity.this);
.dialogManualStart.getwindow()setBackgroundDrawableResource(R.color.transparent);
dialogManualStart.requestwindowFeature(MainActivity.this.getwindow()FEATURE_NO_Title.);
dialogManualStart.setContentVIEw(输入);
dialogManualStart.show();

它总是,无论我使用什么代码,看起来像这样:

如您所见,它总是填满屏幕的宽度.

问题:谁能告诉我为什么?

========编辑1 =============

我将button更改为“wrap_content”(根据Boogers的建议),然后它看起来像这样:

这是非常奇怪的行为,而不是我的预期.

如果我将其更改为“match_parent”,则将其更改为“full wIDth”,即它从左向右延伸.

解决方法 这是你的问题:
<button            androID:ID="@+ID/jobvIEw_pickup_start_submit"            androID:layout_wIDth="fill_parent"...

将其从“fill_parent”更改为“wrap_content”或“match_parent”

总结

以上是内存溢出为你收集整理的android – Popup(使用PopupWindow或Dialog)填充屏幕的宽度没有明显的原因全部内容,希望文章能够帮你解决android – Popup(使用PopupWindow或Dialog)填充屏幕的宽度没有明显的原因所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1135491.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存