I want to place a background image in a RelativeLayout. The background image has got some objects in it, like a chair, a table, some cards, etc.
android:background="@drawable/remy_menu_background" but the damn thing stretches according the the screen, the cards and table look stretched.
How should i go about doing this, so it looks ok on any screen?
You can use an XML drawable that uses the tag to disable the stretching:
<bitmap android:src="@drawable/background" android:gravity="center" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/main_backgroundImage"
android:layout_width="match_parent" // comment: stretches picture in the width if too small.
use "wrap_content" does not stretch, but leaves space
android:layout_height="match_parent" // in my case I always want the height filled
android:layout_alignParentTop="true"
android:scaleType="centerCrop" // will crop picture left and right , so it fits in height and keeps aspect ratio
android:contentDescription="@string/image"
android:src="@drawable/your_image" />
<LinearLayout
android:id="@+id/main_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With