定制的ViewGroup的例子吗?例子、ViewGroup

2023-09-03 23:06:54 作者:白鹿饮清溪

我搜索在这里SO,谷歌,对android文档...

I searched here on SO, on Google, on the android docs...

但我找不到code单段自定义的ViewGroup的例子,我觉得顶多一些模糊的解释...

But I cannot find a single snippet of code with a example of custom viewgroup, I find at most some vague explanations...

有人可以提供吗?你如何做一个ViewGroup中,你可以把它的孩子,你想要什么?

Can someone provide one? How you make a viewgroup where you can put its children where you want?

推荐答案

我想看看最简单的例子就是源AbsoluteLayout.java

I think the simplest example to look at is the source for AbsoluteLayout.java

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/AbsoluteLayout.java

您需要重写onMeasure来衡量孩子,onLayout进行定位。

You need to override onMeasure to measure the children and onLayout to position them.

我有显着更复杂的ViewGroup code,我可以分享,如果你想为好。

I have strikingly more complicated ViewGroup code I can share as well if you want.