Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. Layout background stretches

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?

like image 957
AndreiBogdan Avatar asked Mar 04 '26 14:03

AndreiBogdan


2 Answers

You can use an XML drawable that uses the tag to disable the stretching:

<bitmap android:src="@drawable/background" android:gravity="center" />
like image 114
Romain Guy Avatar answered Mar 07 '26 06:03

Romain Guy


<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>
like image 37
user3048111 Avatar answered Mar 07 '26 07:03

user3048111