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. MMS from/to location?

Hi,

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 (http://74.125.95.132/search?
q=cache:uanGCG1YrPcJ:www.miniware.net/docs/OMA-MMS-ENC-V1_2-20050301-
A.pdf+multimedia+message+service+protocol&cd=8&hl=en&ct=clnk&gl=us),
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?

Thanks,

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
{
        @Override
        public void onCreate( Bundle savedInstanceState )
        {
                super.onCreate( savedInstanceState );
                setContentView( R.layout.main );
        }

        @Override
        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"?>
  <com.test.MyCustomView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  />

MyCustomView.java 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 );
        }

        @Override
        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="http://schemas.android.com/apk/res/
android"
    android:id="@+id/dooferFrame"
    android:layout_width="200dip"
    android:layout_height="200dip"
    android:background="#80ff0000" >
    <TextView
        android:id="@+id/doofer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</FrameLayout>

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

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