Android image tiled implementation

Source: Internet
Author: User
1   We have all seen the tile effect, so how can we achieve it? In fact, we mainly use the API. We can create a new bitmap at the beginning,, no one has ever thought about how to do this. So let's talk about the second method. XML is used. We have mentioned two methods above, but Android is very powerful. That is to say, we still have the third method, that is, we can draw it by ourselves, so let's take a look.CodeRight:  2   3 1 First, use the API provided by the system.  4   5 Bitmap bitmap = Bitmapfactory. decoderesource (getresources (), R. drawable. PIC );  6    7   8   // Bitmap = bitmap. createbitmap (100, 20, config. argb_8888 );  9 Bitmapdrawable drawable = New  Bitmapdrawable (Bitmap );  10   Drawable. settilemodexy (tilemode. Repeat, tilemode. Repeat );  11 Drawable. setdither ( True  );  12   View. setbackgrounddrawable (drawable );  13   14   15 2 ) Second, we use XML for easy implementation.  16   17 <Bitmap xmlns: Android = "http://schemas.android.com/apk/res/android" Android: src = "@ drawable/IMG" 18 Android: tilemode = "repeat"/> 19   20 3 (3) Draw it by yourself.  21   22   Public   Static Bitmap createrepeater ( Int  Width, bitmap SRC ){ 23   Int Count = (width + SRC. getwidth ()-1 )/ SRC. getwidth ();  24   25 Bitmap bitmap = Bitmap. createbitmap (width, SRC. getheight (), config. argb_8888 );  26 Canvas canvas = New  Canvas (Bitmap );  27   28   For ( Int Idx = 0; idx <count; ++Idx ){  29 Canvas. drawbitmap (SRC, idx * SRC. getwidth (), 0, Null  );  30   }  31   32   Return  Bitmap;  33 }
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.