The development of the project needs to develop a beautiful interface, some of which require lace
For example:
If transduction cut the whole piece, then he only applies to the resolution of the phone, if placed on other mobile phones or on the tablet, he will be stretched, used. 9 The same picture will be stretched, then how to do?
In this case, we had to cut out the part of the wavy line that repeats:
Img_wave.png
After we get this part, we start customizing a view, drawing the repeating part of the landscape with the OnDraw of the view,
Before drawing, we need to enlarge the img_wave to the view height:
Float scale = Getmeasuredheight () *1f/bitmap.getheight (); Float width = bitmap.getwidth () *1f*scale;
You also need to calculate the number of draws to achieve the best results:
Wavecount = (int) (Getmeasuredwidth () *1f/bitmap.getwidth ()) +1;
The reason for the above +1 is because let it be one more, enough to fill,
+ 1 after width beyond the view width, then recalculate the drawing width and scale of the IMG_WAVW:
Wavewidth = width-((Width*wavecount-getmeasuredwidth ())/wavecount); Wavescale = Wavewidth*1f/bitmap.getwidth ();
Finally, draw the waves horizontally:
Matrix.setscale (Wavescale, Wavescale); for (int i = 0; i < Wavecount; i++) {Canvas.drawbitmap (Bitmap_wave.get (), Matrix , paint); Matrix.posttranslate (wavewidth, 0);}
Finally, the following:
Isn't it great? Finally posted code, hoping to help everyone:
/** * Seamless Lace * @author touch_ping * */public class Wavelineview extends View {private final static int waveres = R.drawable. Img_wave;private static softreference<bitmap> bitmap_wave;//Background Private context mcontext;private static Paint Paint;private static Matrix matrix;private static float wavewidth;private static float wavescale;private static int Waveco Unt;public Wavelineview (Context context) {super (context); init (context);} Public Wavelineview (context context, AttributeSet Attrs) {Super (context, attrs, 0); init (context);} private void init (context context) {Mcontext = context;} @Overrideprotected void OnDraw (canvas canvas) {Super.ondraw (canvas), if (paint==null) {paint = new paint ();} if (matrix==null) {matrix = new matrix ();} if (Bitmap_wave==null | | bitmap_wave.get () ==null) {//Generate bitmap from resource file bitmap bitmap = Bitmapfactory.decoderesource (getresour CES (), waveres), float scale = Getmeasuredheight () *1f/bitmap.getheight (), Float width = bitmap.getwidth () *1f*scale; Wavecount = (int) (GETMEASUREDWIDTH () *1f/width) +1;wavewidth = width-((Width*wavecount-getmeasuredwidth ())/wavecount); Wavescale = wavewidth*1f/ Bitmap.getwidth (); bitmap_wave = new softreference<bitmap> (bitmap);} Matrix.setscale (Wavescale, Wavescale); for (int i = 0; i < Wavecount; i++) {Canvas.drawbitmap (Bitmap_wave.get (), Matrix , paint); Matrix.posttranslate (wavewidth, 0);}}
Android Draw Lace View-wavelineview