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
Introduction to the resources of Master Xian’s in...
Students from the School of Electrical Engineerin...
How did the talented painter Lippi learn from oth...
With the upgrading of consumption, Chinese people...
I look older but my voice is younger, so please d...
This year, the iPhone 13 series finally cancelled...
Many brands are accustomed to using the marketing...
Chinese New Year Also in the circle of friends Th...
This year's Double 11 once again made domesti...
1. Why should we pay attention to the homepage de...
During the Cold War between the United States and...
The arrival of iPhone X means that Apple has fina...
The era of "traffic is king" is over, a...
How many days will the Dragon Boat Festival be th...
On August 24, Google announced on Monday local ti...