If you plan to completely customize a View, you need to implement the View class (all Android Views are implemented in this class) and implement the onMeasure(...) method to determine the size and the onDraw(...) method to confirm the drawing. Customizing View is divided into 6 steps ***step
2. Implement the paint brush class There are two brushes in this article
3. Override the onMeasure(…) method Implementing this method tells the parent container how to abandon the custom View. You can determine the height and width of your View by providing measureSpecs. The following is a square. Confirm that its width and height are the same.
Notice: This method requires at least one setMeasuredDimension(..) call, otherwise an IllegalStateException error will be reported. 4. Implement the onSizeChanged(…) method This method is how you get the current width and height of the View. Here we calculate the center and radius.
5. Implement the onDraw(…) method This method provides how to draw the view, and the Canvas class it provides can be used for drawing.
6. Add your View
That’s it. Customizing View is not as difficult as you think. |
<<: 10 Tips for Solving Problems in Android Development
>>: Android Studio debugging tips you don't know
(Image source: CCTV.com screenshot) These two pho...
Recently, WeChat Mini Programs have once again ma...
On Xiaohongshu, where content is king, being able...
The theme of Microsoft's latest press confere...
The COVID-19 pandemic has brought online office w...
The launch of mini programs has brought convenien...
Now there are still a lot of businesses who see t...
1. Fission! Fission! In the past six months, fiss...
01 Most of the genes we once had have not disappe...
As of now, the total box office of the film "...
JavaScript core principles are explained in detai...
In the past, when I heard about elders getting st...
520 is here again, are you ready to confess your ...
In March 2022 , due to the frequent outbreaks of ...
Do you often encounter the following scenarios: T...