tags:

views:

60

answers:

0

The following XML doesn't work to center an ImageView in a LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/myimg" 
        android:layout_width="36dip"
        android:layout_height="36dip"
        android:scaleType="fitXY"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/my_background"
    />
</LinearLayout>

RelativeLayout works:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/myimg" 
        android:layout_width="36dip"
        android:layout_height="36dip"
        android:scaleType="fitXY"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_background"
    />
</RelativeLayout>

Could you someone tell me why? Thanks!