Android. Avoid scaling of background
Asked Answered
B

1

10

In a start activity of our android application we're using a linearlayout with an background image for whole space.

The image size is 320x480 - the same as device resolution, we're using for testing.

The problem is, the image will be scaled und looks not so nice.

I tried to use imageview instead, but I've got black borders.

Some ideas, how to avoid scaling or how to get the proper size for background image?!

Thank you in advance.

Mur.

Burner answered 15/10, 2010 at 16:16 Comment(0)
A
34

Create a background.xml file in res/drawable and use the following:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/background_image"
    android:gravity="center"/>

And use this background.xml as your LinearLayout's background.

Autocade answered 15/10, 2010 at 17:49 Comment(4)
could you explain a bit more? what should I write in background.xml?!Burner
it works, thank you :) just one notice for other: don't forget xmlns:android="schemas.android.com/apk/res/android"Burner
This answer could be a lot more helpful, I'm trying to create an xml file now, if I try through the android studio GUI it only lets me make a values or layout files and puts them in the wrong folders, what tags do I need in the xml file? I've tried background, drawable, layout, nothing works!Stertorous
What if I don't want to use a bitmap but another drawable?Pimental

© 2022 - 2024 — McMap. All rights reserved.