一次获取 LinearLayout 中的所有子视图 [英] Get all child views inside LinearLayout at once
本文介绍了一次获取 LinearLayout 中的所有子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 LinearLayout
,它包含几个子 TextViews
.如何使用循环获取该 LinerLayout 的子视图?
I have a LinearLayout
, which contains several child TextViews
. How can I get child views of that LinerLayout using a loop?
推荐答案
使用 getChildCount()
和 getChildAt(int index)
.
示例:
LinearLayout ll = …
final int childCount = ll.getChildCount();
for (int i = 0; i < childCount; i++) {
View v = ll.getChildAt(i);
// Do something with v.
// …
}
这篇关于一次获取 LinearLayout 中的所有子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文