Android image tiled implementation

Source: Internet
Author: User

The implementation of the android screen allows the same picture to be arranged in order into an entire large image. How can this problem be achieved? Take a look at the three implementation methods. We recommend that you use the second implementation method, which is simple and easy to maintain.
 
(1) The first method is to use the API provided by the system.
 
Bitmap bitmap = bitmapfactory. decoderesource (getresources (), R. drawable. PIC );

 
// Bitmap = bitmap. createbitmap (200, 30, config. argb_8888 );
Bitmapdrawable drawable = new bitmapdrawable (Bitmap );
Drawable. settilemodexy (tilemode. Repeat, tilemode. Repeat );
Drawable. setdither (true );
View. setbackgrounddrawable (drawable );
 
 
(2) The second method is to use XML for easy implementation.
 
<Bitmap xmlns: Android = "http://schemas.android.com/apk/res/android" Android: src = "@ drawable/IMG"
Android: tilemode = "repeat"/>
 
3) The third method is to draw it by yourself.
 
Public static Bitmap createRepeater (int width, Bitmap src ){
Int count = (width + src. getWidth ()-1)/src. getWidth ();
 
Bitmap bitmap = Bitmap. createBitmap (width, src. getHeight (), Config. ARGB_8888 );
Canvas canvas = new Canvas (bitmap );
 
For (int idx = 0; idx <count; ++ idx ){
Canvas. drawBitmap (src, idx * src. getWidth (), 0, null );
}
 
Return bitmap;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.