简体   繁体   English

Android:从视图中获取Viewgroup?

[英]Android: get Viewgroup from the view?

Is there any way to get the ViewGroup from a view? 有没有办法从视图中获取ViewGroup? I'm trying to create a custom array adapter and it needs the viewgroup 我正在尝试创建自定义数组适配器,它需要viewgroup

Depending on which ViewGroup you are after, you can get the parent of your view and cast it to a ViewGroup : 根据您所使用的ViewGroup ,您可以获取视图的父级并将其ViewGroup转换为ViewGroup

(ViewGroup)view.getParent() // this can be done to get any level in your view hierarchy 

or you can cast the view itself as a ViewGroup : 或者您可以将视图本身转换为ViewGroup

(ViewGroup)view

Basically, find the view you want in your view hierarchy and cast it to ViewGroup 基本上,在视图层次结构中找到所需的视图并将其ViewGroupViewGroup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM