且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在自定义视图中添加视图?

更新时间:2022-10-16 16:40:44

您的自定义视图需要扩展ViewGroup或扩展ViewGroup的其他类之一.例如,如果这些布局适合您的自定义视图的需要,则可以从RelativeLayoutLinearLayout扩展.

Your custom view needs to extend ViewGroup or one of the other classes that extends ViewGroup. For example, you could extend from RelativeLayout or LinearLayout if those layouts fits what your custom view needs to do.

请记住,甚至布局类也只是另一个View.他们只是碰巧拥有添加其他视图作为子视图的方法,并且具有递归地度量和绘制其子视图的代码.

Remember, even the layout classes are just another View. They just happen to have methods to add other views as children and have code to recursively measure and draw their children.