Shape,roundrectshape,arcshape in Android, OvalShape

Source: Internet
Author: User


When doing the Android project to encounter a dynamic in the code to a group to add a certain round corner of the background is not used in the Shape.xml file to use the code, looked at a good time to understand the meaning of the Roundrectshape parameters, record down the province later forget. First, a diagram of the crossing network, representing the inheritance relationship between the several classes.

1. Roundrectshape

Float[] outerradii = {20, 20, 30, 30, 40, 40, 50, 50};//outer rectangle top left, top right, bottom right, bottom left corner radius rectf inset = new RECTF (100, 100, 100, 100);// Inner rectangle outside Rectangle, upper left corner x, y distance, lower right corner x, y distance float[] innerradii = {20, 20, 20, 20, 20, 20, 20, 20};//rectangle fillet radius roundrectshape roundrectshape = New Roundrectshape (outerradii, inset, innerradii); Shapedrawable drawable = new Shapedrawable (roundrectshape);d rawable.getpaint (). SetColor (Color.Black); Drawable.getpaint (). Setantialias (True);d rawable.getpaint (). SetStyle (Paint.Style.STROKE);// Stroke Mimage.setbackground (drawable);


The code in Roundrectshape (float[] outerradii, RECTF inset,float[] innerradii) has three parameters, the first and second are 8 numeric arrays, representing the rounded radii of the 4 corners of the rectangle, At the beginning of the doubts in this 8 number, how also do not understand, test several times to understand. These 8 arrays, starting from the upper left, represent the radii of each radian, for example, the upper left corner of the upper left is composed of two sides, left and top, the first number represents the top edge of the left side of the radius, the second represents the top of the circle radius, from the upper left corner, the upper right corner, the lower right corner, and so on the lower left corner and so on exactly eight numbers. The first parameter represents the outer corner, which represents the inner corner, that is, the large rectangular set of small rectangles. The second parameter represents the position of the inner rectangle, the distance from the large rectangle to the left, top, right, and bottom. If the next two arguments are null, then there is only one large rectangle. The results are as follows:

2. Arcshape Draw round or fan

New Arcshape (0, -300new  shapedrawable (Shape);d rawable.getpaint (). SetColor (Color.Black); Drawable.getpaint (). Setantialias (true);d rawable.getpaint (). SetStyle (Paint.Style.STROKE); Mimage.setbackground (drawable);

Arcshape (float startangle, float sweepAngle) has two parameters, the starting Radian, the arc to be crossed, the above example is written in negative numbers, then the arc is drawn counterclockwise, if positive, the arc is drawn clockwise. If it is 360 degrees, then it is a circle, the radius of the circle is the size of your imageview itself to decide. The effect is as follows:

3. OvalShape Ellipse

OvalShape OvalShape = new OvalShape (); Shapedrawable drawable = new Shapedrawable (ovalshape);d rawable.getpaint (). SetColor (Color.Black);d Rawable.getpaint ( ). Setantialias (True);d rawable.getpaint (). SetStyle (Paint.Style.STROKE); Mimage.setbackground (drawable);

  

Draw an ellipse, the same width of the ellipse by your carrier to decide, I here is imageview, need to note is * * If the width and height of imageview is a circle * *, the effect is as follows:

Shape,roundrectshape,arcshape in Android, OvalShape

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.