Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有什么方法可以从视图中获取 ViewGroup 吗?我正在尝试创建一个自定义数组适配器,它需要视图组
根据ViewGroup您所追求的,您可以获取视图的父级并将其转换为ViewGroup:
ViewGroup
(ViewGroup)view.getParent() // this can be done to get any level in your view hierarchy
或者您可以将视图本身转换为ViewGroup:
(ViewGroup)view
基本上,在视图层次结构中找到您想要的视图并将其转换为ViewGroup