<?xml version="1.0" enCoding="utf-8"?><ScrollVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:background="@drawable/tile_bg" ><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:paddingtop="10dp" > <linearLayout androID:ID="@+ID/layout_0" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <!-- vIEw stuff here --> </linearLayout> <!-- more linear layouts as siblings to this one --></linearLayout>
我实际上有大约7个linearLayout项目,每个ID都从layout_0等增加.我想要能够掌握根linearLayout下的所有linearLayout项目.我需要将一个ID放在根目录下,通过ID找到所有其他ID,或者我可以通过类型获取它们.
我用来夸大布局的代码是:
VIEw vIEw = (VIEw) inflater.inflate(R.layout.flight_details,container,false);
我读到某个地方可以迭代VIEwGroup的子项,但这只是一个VIEw.
通过类型获取一群孩子的最佳方式是什么?
解决方法 这应该让你在正确的轨道上.linearLayout rootlinearLayout = (linearLayout) findVIEwByID(R.ID.rootlinearLayout);int count = rootlinearLayout.getChildCount();for (int i = 0; i < count; i++) { VIEw v = rootlinearLayout.getChildAt(i); if (v instanceof linearLayout) { ... }}总结
以上是内存溢出为你收集整理的Android:如何按类型查找视图全部内容,希望文章能够帮你解决Android:如何按类型查找视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)