Android Image horizontal Repeat tile (repeat x)

Source: Internet
Author: User

= The diagram used to repeat the display

1. The simplest way
Create Wave_repeat.xml<?XMLversion="1.0"encoding="Utf-8"?>
<Bitmapxmlns:android="Http://schemas.android.com/apk/res/android"
android:src="@drawable/wave"
Android:tilemode="Repeat" />
use in Layout<View
Android:layout_width="Match_parent"
Android:layout_height="Wrap_content"
Android:background="@drawable/wave_repeat"/>
There is one problem with this approach, the last oneRepeatthe picture may not be a complete picture, maybe just a part.
: (About two vertical lines are added later)

2. Make sure that the last duplicate picture is complete, just a few complete same picture x axis repetitionResources res =Context. Getresources ();
Bitmap Bitmap = Bitmapfactory.decoderesource (res, r.drawable.Wave);
Holder.Viewwave. Setimagebitmap (Bitmaphelper.createrepeater (ScreenWidth, bitmap));//screenwidth for screen width (or display of picturesImageViewwidth)

methods in the Bitmaphelper.java PublicStaticBitmap Createrepeater (intwidth, Bitmap src) {
intcount = (width + src.getwidth ()-1)/Src.getwidth (); //Calculates the minimum number of repetitions required to fill the width of the tile
Bitmap Bitmap = Bitmap.createbitmap (Src.getwidth () *count, Src.getheight (), Config.argb_8888);
Canvas Canvas =NewCanvas (bitmap);
for(intidx = 0; idx < count; ++idx) {
Canvas.drawbitmap (SRC, idx * src.getwidth (), 0,NULL);
}
returnbitmap;
}

set ImageView's scaletype to fitxy in Layout < ImageView
Android:id="@+id/view_wave"
Android:layout_width="Match_parent"
Android:layout_height="Wrap_content"
Android:scaletype="Fitxy"/>

:

Android Image horizontal Repeat tile (repeat x)

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.