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. Extract one example from a project with many

I have an api examples project with about 100 examples in it.
How do I get just one out - I mean I need java files, resources,
R.java, manifest, layout, string xmls etc etc.

Tried all sorts of things and always some crapy unsolvable error.

Is there a simple way to get one example java + associated files
form the hundreds in the project?

-- 

2. ContextMenu on TableLayout: how to get selected item position?

I had the similar issue and solved it with a work around. In your table row
add a TextView and makes its visibility GONE and set its text as 0,1,2,4...
for respective rows. Add a single listener for each row. When some row is
clicked the listener will give you a clicked view. From this view get the
text view from this text view the index.





--
Best Regards,
Atif Gulzar

I  Unicode, zln 






> 

3. ViewFlipper switching views on screen orientation change

4. Salam kenal... Again..

5. pressing home button to launch the web browser

6. xml updation

7. emulator not getting launched with 2.1 platform