3 ways to implement an Android image tiling effect

Source: Internet
Author: User

HTML tile effect, then we are how to achieve that, we actually mainly use the API, we start new a bitmap, we can, then we say the second method, it is used in XML, above we said two methods, But Android is very powerful, that is to say we have a third method, that is, we draw it ourselves, the code is as follows:

The first type:

(1) The first implementation of Java code using the system-provided API: Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.pic);//bitmap = Bitmap.createbitmap (+, config.argb_8888); Bitmapdrawable drawable = new Bitmapdrawable (bitmap);d rawable.settilemodexy (Tilemode.repeat, tilemode.repeat); Drawable.setdither (True); view.setbackgrounddrawable (drawable);

  

The second type:

(2) The second kind we use XML to easily implement Java code:< bitmap xmlns:android= "http://schemas.android.com/apk/res/android" android:src= "@ Drawable/img "android:tilemode=" repeat "/>

  

The third type:

(3) The third kind draws out the Java code: public static Bitmap createrepeater (int width, Bitmap src) {int count = (width + src.getwidth ()-1)/SR C.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;}

  

3 ways to implement an Android image tiling effect

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.