Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you scale and tile a bitmap drawable being used as a background?

I have the following code in a drawable bitmap xml file. And the background of a linearLayout set to it.

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

The image tiles OK, but it doesn't scale. What do I have to do/fix to get it to scale?

Thanks

like image 676
cnfw Avatar asked Jun 25 '12 19:06

cnfw


People also ask

What is a bitmap drawable?

android.graphics.drawable.BitmapDrawable. A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object. It can be defined in an XML file with the <bitmap> element.

Which function is used is to load a drawable image resource?

getDrawable(res, R. drawable. my_image, null);

Which drawable definition allows you to achieve the shape?

XML Drawables Shape Drawables are XML files which allow to define a geometric object with colors, borders and gradients which can get assigned to Views . The advantage of using XML Shape Drawables is that they automatically adjust to the correct size.


1 Answers

In my experience it is better to create different sized bitmaps for each density you are targeting. That way you don't have to worry about these scale attributes and get crisp results on any device.

These scale attributes are not defined for BitmapDrawables. They exist for ScaleDrawables which are meant to scale another drawable. Have a look at:

http://developer.android.com/guide/topics/resources/drawable-resource.html#Scale

like image 150
tiguchi Avatar answered Sep 28 '22 05:09

tiguchi