android: how to align image in the horizontal center of an imageview?

Yang picture Yang · Apr 6, 2010 · Viewed 214.1k times · Source

I've tried all scaletypes, but all of them result in the image to be at the left corner of the imageview.

 <ImageView
    android:id="@+id/image"
    android:scaleType="centerInside"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:layout_marginRight="6dip"
    android:background="#0000" 
    android:src="@drawable/icon1" />

Answer

Neil Chan picture Neil Chan · May 2, 2011
<ImageView
    android:id="@+id/img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />