slhck
slhck

Reputation: 38672

Why does my striped background scale with such a bad quality?

I have an activity that includes a striped background image. Click to enlarge – this is the original image I'm using. There's also a version with a logo for another activity.

It looks fine as is. I set it as a background in the activity through XML, something like this.

I need the hack as an ImageView to be able to properly centerCrop a logo in the background, but this is irrelevant to the issue, as it persists when setting the background for the RelativeLayout and removing the ImageView.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/background_striped" />

Note that since there has to be a logo inside the image, I can't stretch it artificially or have it repeat.


In the layout preview screen, it looks like this:

In the emulator, it looks like this:

As you can see, it looks quite bad, compared to how I'd expect it:

Naturally, I've created versions of the striped background for all display resolutions (from ldpi to xhdpi), but they always seem to be scaled in a pretty bad way.

Is there any way to get the background scaled in a higher quality? Just using the xhdpi version won't result in better quality—it will just make the scale result worse and more washed out.

Upvotes: 1

Views: 669

Answers (2)

adneal
adneal

Reputation: 30804

Try using repeat. I tested it and it seems to look fine.

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

Upvotes: 1

liarspocker
liarspocker

Reputation: 2444

For scalable drawables it is better to use a 9-patch. You can create one with your small striped background image using the android 9-patch tool:

http://developer.android.com/tools/help/draw9patch.html

Upvotes: 1

Related Questions