Android implements rounded image with stroke
Using the learned bitmapshader rendering class, we implement a rounded image with stroke.
Specific implementation:
The layout file RES / layout / main.xml used to display custom drawing classes:
Open mainactivity, create an internal class named MyView in the file, inherit android.view.view class, add construction method and override OnDraw (canvas) method, and draw in it:
In the OnDraw (canvas) method, first define a brush and set it to use the anti aliasing function, then define a background, then define an area of the rounded rectangle to be drawn, translate the canvas 40 pixels on the X axis, 20 pixels on the Y axis, and then draw a black 2-pixel rounded rectangle as the edge of the picture, Finally, draw a rounded rectangle rendered with bitmapshader. The specific code is as follows:
MainActivity:
The operation effect is shown in the figure
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.