弹出窗口(使用PopupWindow或Dialog)填满屏幕的宽度无缘无故 [英] Popup (using PopupWindow or Dialog) fills the width of the screen for no apparent reason
问题描述
我想,弹出的行为! =)
I am trying to get a popup to behave! =)
问题是,在弹出的填充宽度整个屏幕,即使布局清楚地说,它应该WRAP_CONTENT。如果我使用对话框或PopupWindow这并不重要。
The problem is that the popup "fills the width" of the entire screen, even though the layout clearly says that it should "wrap_content". It doesnt matter if I use Dialog or PopupWindow.
首先,在弹出的XML布局,popup_message.xml:
First, the XML layout of the popup, 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>
而code我使用的:
And the code I am using:
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, LayoutParams.WRAP_CONTENT, true);
View v = findViewById(R.id.main_deviceInfoBar);
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
我也试过这样的:
I have also tried this:
对话框dialogManualStart =新的对话框(MainActivity.this);
。dialogManualStart.getWindow()setBackgroundDrawableResource(R.color.transparent);
dialogManualStart.requestWindowFeature(MainActivity.this.getWindow()FEATURE_NO_TITLE);
dialogManualStart.setContentView(输入);
dialogManualStart.show();
Dialog dialogManualStart = new Dialog(MainActivity.this); dialogManualStart.getWindow().setBackgroundDrawableResource(R.color.transparent); dialogManualStart.requestWindowFeature(MainActivity.this.getWindow().FEATURE_NO_TITLE); dialogManualStart.setContentView(input); dialogManualStart.show();
和它总是,无论什么code我用,看起来是这样的:
And it always, no matter what code I use, looks like this:
正如你所看到的,它总是填充屏幕的宽度。
As you can see, its always filling the width of the screen.
问:谁能告诉我,为什么
========编辑1 =============
======== EDIT 1 =============
我改成WRAP_CONTENT(据鼻屎建议)按钮,然后它看起来像这样:
I changed the Button to "wrap_content" (according to Boogers suggestion), and then it looks like this:
这是很奇怪的行为,不出我所料。
This is very strange behaviour, not what I expected.
如果我把它改为match_parent,将其带回全宽,由左到右,即它扩展的所有道路。
If I change it to "match_parent", its back to "full width", ie it extends all the way from left to right.
推荐答案
这是你的问题:
<Button
android:id="@+id/jobview_pickup_start_submit"
android:layout_width="fill_parent"
...
更改,从FILL_PARENT到WRAP_CONTENT或match_parent
Change that from "fill_parent" to "wrap_content" or "match_parent"
这篇关于弹出窗口(使用PopupWindow或Dialog)填满屏幕的宽度无缘无故的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!