image background - how to repeat an image rather than strech it

by liordav » Wed, 12 Jan 2011 16:57:49 GMT


Sponsored Links
 Hi,
I have an image I want to use as a background to some layout.
the problem is the image contains a texture of slant lines, so if i
use a 1 pixel width image or a 9 patch the image is stretched and the
texture is Twitching, so i can see the slant lines as latitude lines.
I saw that he android emulator uses a similar texture in the progress
bar indeterminate animation, is there a special/simple definition to
order the background image to repeat itself rather than stretch? is
there a way to do it with 9 patch, cause eventualy i also need the
corners to be round.
thanks for the help.

-- 



Re: image background - how to repeat an image rather than strech it

by Doug » Thu, 13 Jan 2011 07:26:17 GMT


 See BitmapDrawable and its related xml configuration documentation if
you want to tile an image for the background of a View.




-- 


Sponsored Links


Re: image background - how to repeat an image rather than strech it

by Muhammad Ali » Thu, 13 Jan 2011 16:07:05 GMT


 You can create a bitmap in memory, using your own file and draw it in
background. It will help you like the repeat image.






-- 



Re: Re: image background - how to repeat an image rather than strech it

by Richard Leggett » Sat, 15 Jan 2011 01:51:25 GMT


 An easy way of making a bitmap repeat is to create an XML file in the drawable 
folder which looks something like this:

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

"background" is a PNG in the same folder, it doesn't sound like you need a 9 
patch in this case. Simply assign @drawable/repeatingbackground or whatever you 
called the file, in place of the original bitmap. 

As for rounding corners, you can subclass the view you are rendering (let's say 
an ImageView) and use clipping to mask the corners, there are a few examples 
here:

 http://stackoverflow.com/questions/2459916/how-to-make-an-imageview-to-have-rounded-corners 

I'm presenting techniques here that are more generalised and re-useable and not 
a specific one-off which could be better performance-wise (so if you are making 
a component that's like a progress bar, you'd do this clipping and 
repeat-bitmap drawing in the onDraw() rather than increasing rendertime by 
compositing a separate RoundedImageView and a repeatable BitmapDrawable 
described above).

Rich







-- 



Other Threads

1. [WTS] HTC Desire brown mulus lengkap

As subject,

HTC Desire, beli dari boss gadget milis.
Warna brown, mulus no dent.
Anti glare sejak pertama & jelly case warna hitam
Lengkap dus buku charger hf belum pernah dipake, include microSD 4GB
Kondisi rooted + installed MIUI ROM

Japri ke ja...@mnurihsan.com
Lokasi di Jakarta Selatan (prefer COD aja)

Cheers,

-- 
===============
"

2. OOT: ArDrone Testing

Abang rive mang uda plg keren.. pgnnnnn pgn ar drone ya..



-- 
===============
"

3. Getting the already set alarm (AlarmManager)

4. Arabic Support in FROYO

5. Audio Capture Play Slowly

6. [SpicaUser - WTShare] Criminal's CM Alpha 8.1. ++

7. CallBack for the recorded block in MediaRecorder