Android to achieve tile image effect _android

Source: Internet
Author: User

Recently developed the app, the artist designed a jagged edge effect of the background image, only gave me a sawtooth, and then need to tile display Sawtooth effect:

There are two ways to implement tiled images in Android:

(1) Define the tiled bitmap in the drawable file in drawable

<?xml version= "1.0" encoding= "Utf-8"?> <bitmap xmlns:android=
"http://schemas.android.com/apk/res/" Android "
 android:src=" @mipmap/ic_border_cupons_left "
 android:tilemode=" repeat "
 >

</ Bitmap>

(2) Set in code

/** * initialization sawtooth Background * @param holder/private void INITVIEWBG (Viewholder holder) {/ /Set the small rounded background of the content area tile Bitmap Topbitmap = Bitmapfactory.decoderesource (Mcontext.getresources (), R.mipmap.ic_border_cupons_
  left);
  Bitmapdrawable leftdrawable = new Bitmapdrawable (Mcontext.getresources (), topbitmap);

  Leftdrawable.settilemodey (Shader.TileMode.REPEAT);
  Bitmap Bottombitmap = Bitmapfactory.decoderesource (Mcontext.getresources (), r.mipmap.ic_border_cupons);
  Bitmapdrawable rightdrawable = new Bitmapdrawable (Mcontext.getresources (), bottombitmap);

  Rightdrawable.settilemodey (Shader.TileMode.REPEAT); if (Build.VERSION.SDK_INT >= build.version_codes.
   Jelly_bean) {holder.favourItemBgLeft.setBackground (leftdrawable);
  Holder.favourItemBgRight.setBackground (rightdrawable);
   else {holder.favourItemBgLeft.setBackgroundDrawable (leftdrawable);
  Holder.favourItemBgRight.setBackgroundDrawable (rightdrawable); }

 }

One of the first in the XML file to set up some of the models may have an adaptation problem, so it is recommended to use code to achieve the image tiling effect.

This is the entire content of this article, I hope to learn more about Android software programming help.

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.