大佬教程收集整理的这篇文章主要介绍了android – Popup(使用PopupWindow或Dialog)填充屏幕的宽度没有明显的原因,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题是弹出窗口“填充整个屏幕的宽度”,即使布局清楚地表明它应该“wrap_content”.如果我使用Dialog或PopupWindow无关紧要.
首先,弹出窗口的XML布局,popup_message.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://scheR_420_11845@as.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)填充屏幕的宽度没有明显的原因所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。