Android tiled background image

Source: Internet
Author: User

There are three main ways to tile images for Android: 1) system API; 2) xml configuration; 3) custom Rendering

Method 1:System API implementation

 
Bitmap bitmap = bitmapfactory. decoderesource (getresources (), R. drawable. PIC); // bitmap = bitmap. createbitmap (100, 20, config. argb_8888); bitmapdrawable drawable = new bitmapdrawable (Bitmap); drawable. settilemodexy (tilemode. repeat, tilemode. repeat); drawable. setdither (true); view. setbackgrounddrawable (drawable );

Method 2:XML implementation

XML Path: Res/drawable/BG. xml

 
<Bitmap xmlns: Android = "http://schemas.android.com/apk/res/android" Android: src = "@ drawable/IMG" Android: tilemode = "repeat"/>

Method 3:Custom drawing

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 = new canvas (Bitmap); For (INT idx = 0; idx <count; ++ idx) {canvas. drawbitmap (SRC, idx * SRC. getwidth (), 0, null);} return bitmap ;}

Reference recommendations:

Android activity tiled background image

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.