5

I have this layout for PopUpWindow:

<?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>

I've tried adding android:margin = "10dp" but it won't work, it is still on the upper right with no margin at all.

Thanks.

lorraine batol
  • 6,001
  • 16
  • 55
  • 114
  • put the extra code in xml android:layout_gravity ="center_horizontal" and see another criteria from the below link http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity – V.J. Aug 27 '12 at 06:25

2 Answers2

3

I have myself not used PopUpWindow but the Android docs show a method:

showAtLocation(View parent, int gravity, int x, int y)

ataulm
  • 15,195
  • 7
  • 50
  • 92
Gaurav Vashisth
  • 7,547
  • 8
  • 35
  • 56
  • There isn't a 4-parameter `showAtLocation` method in `PopupWindow`. @yin03 are you sure this is the correct answer? – Halil Aug 05 '14 at 04:30
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>

or

try Custom PopupWindow Click here

Community
  • 1
  • 1
Manoj Manani
  • 507
  • 4
  • 9
  • 5
    `padding` and `margin` are different things. @yin03 is asking for `margin`. You can see the difference between `padding` and `margin` if parent view's background color is different that PopupWindow. – Halil Aug 05 '14 at 04:28