Следующий код XML не работает, чтобы центрировать ImageView в 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, который неожиданно работает:
<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>
Может кто-нибудь сказать мне, почему? Спасибо!