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

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

Sponsored Links
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="" ;
    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 

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).



Other Threads

1. MMS from/to location?


I am accessing the MMS content provider to get the messages in the MMS
inbox. However, among the columns in the MMS inbox, there are no from/
to location. When I saw the MMS protocol (
it says there should be a "from" and a "to" field. I'm assuming that
these fields are being hidden. Is there any way to get around this and
get the "from/to" field for a MMS programmatically?


2. Why aren't ACTION_UP and ACTION_MOVE Touch Events passed through to custom views?

I have an activity defined as:

public class MyDemo extends Activity
        public void onCreate( Bundle savedInstanceState )
                super.onCreate( savedInstanceState );
                setContentView( R.layout.main );

        public boolean onTouchEvent(MotionEvent me)
                Log.i("MyDemo motion", "" + me.getAction());
                return false;

With this custom view in main.xml

<?xml version="1.0" encoding="utf-8"?>
    android:layout_height="wrap_content"  /> contains

public class MyCustomView
        extends FrameLayout
        implements OnGestureListener
        public MyTest( Context context, AttributeSet attrs )
                super( context, attrs );
                LayoutInflater.from( context ).inflate( R.layout.doofer, this,
true );

        public boolean onTouchEvent(MotionEvent me)
                Log.i("MyCustomView motion", "" + me.getAction());
                return false;

And finally doofer.xml is

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="
    android:background="#80ff0000" >
        android:layout_height="fill_parent" />

So... looking at LogCat we can see the motion events that occur.  The
MyDemo Activity logs down, up and move events perfectly as expected.
However, MyCustomView only logs down events!

Why aren't ACTION_UP and ACTION_DOWN Touch Events passed through to
custom views?

I need to handle the touch events in the custom view (not the
activity) because there are several custom views in the activity and
all of them need to respond individually to fling motions.  Detecting
fling events in the activity wont tell me over which view the fling
event happened.  So i would like to handle the touch events in the
custom view (its a better OO practice than handling it in the

Any Clue?

3. MP4 Composer Node configuration question

4. Playback of video from Browser on Eclair doesn't work

5. Nexus GPS antenna is always active when "Use GPS Satellites" is checked...

6. File Dialog?

7. Iphone development versus Android