Android PopUpWindow - 如何设置边距?

5

我有一个弹出窗口布局:

<?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="wrap_content"
        android:orientation="vertical"        
        android:background="@color/colorbg">    
</LinearLayout>

我尝试添加android:margin = "10dp",但它不起作用,它仍然在右上角,没有任何边距。
谢谢。

将多余的代码放在xml中 android:layout_gravity ="center_horizontal"并查看下面链接中的其他标准http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity - V.J.
2个回答

3

try this android:padding="10dip"

<?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="wrap_content"
    android:orientation="vertical"
 android:padding="10dip"        
    android:background="@color/colorbg">    
</LinearLayout>

或者

尝试自定义弹出窗口点击这里


5
“padding”和“margin”是两个不同的概念。“@yin03”正在询问“margin”。如果父视图的背景颜色与PopupWindow不同,就可以看出“padding”和“margin”的区别。 - Halil

3

PopupWindow 中没有一个四参数的 showAtLocation 方法。@yin03 你确定这是正确的答案吗? - Halil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接