现在的位置: 首页 > 综合 > 正文

根据布局id遍历其内的子控件

2019年05月20日 ⁄ 综合 ⁄ 共 457字 ⁄ 字号 评论关闭

        LinearLayout l = (LinearLayout)getViewById(rv.getLayoutId());
        int childCount = l.getChildCount();
        //遍历下面所有的子控件,判断是否是layout
        for(int i = 0; i < childCount; i++){
            if(l.getChildAt(i) instanceof LinearLayout
                    || l.getChildAt(i) instanceof RelativeLayout
                    || l.getChildAt(i) instanceof TableLayout
                    || l.getChildAt(i) instanceof AbsoluteLayout){
                //操作代码           
                }
        }

抱歉!评论已关闭.