Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView trouble

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

The size of @drawable/peetscoffee_wallpaper is 640x480, but it is not centered horizontally. How can I fix this?

like image 825
alexkipar Avatar asked Dec 22 '22 11:12

alexkipar


1 Answers

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.

like image 140
Yoni Samlan Avatar answered Jan 04 '23 00:01

Yoni Samlan