views:

624

answers:

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView    
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerHorizontal="true"
     android:src="@drawable/wallpaper" />
</RelativeLayout>

Size of "@drawable/peetscoffee_wallpaper" is 640x480 , but it is not centered horisontally. How to fix it?

+2  A: 

Try android:gravity="center", or android:layout_gravity="center", instead of centerHorizontal="true".

However, i doubt this will behave sensibly with an image that size set to wrap_content - you may want to define some image scaling method with android:scaleType (eg fitCenter) and set it to fill_parent rather than wrap_content. 640x480 is bigger than the 320x480 the current real-world Android devices support. Or just scale down that image you're using so the device doesn't have to do the work.

Yoni Samlan