`

android -> 父控件 遍历 子 控件

 
阅读更多

 

布局文件: 

<LinearLayout android:id="@+id/candi_more_row1"
	android:orientation="horizontal"
	android:gravity="center_vertical"
	android:layout_width="match_parent"
	android:layout_weight="1"
	android:layout_height="match_parent">
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_1"
		android:tag="panelCandiBtn_1"
		android:text="水电"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_2"
		android:tag="panelCandiBtn_2"
		android:text="水电"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_3"
		android:tag="panelCandiBtn_3"
		android:text="水电"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_4"
		android:tag="panelCandiBtn_4"
		android:text="水电"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_5"
		android:tag="panelCandiBtn_5"
		android:text="水电"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
</LinearLayout>

 

 

JAVA

LinearLayout lt = (LinearLayout)keyboard_view_zh.findViewById(R.id.candi_more_row1);
for (int i = 0;i < lt.getChildCount(); i++){
	if (lt.getChildAt(i) instanceof Button) { // 若是Button记录下
		Button tb = (Button)lt.getChildAt(i);
		tb.setText("L:"+i);
	}
}

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    android用遍历的方法对界面中控件设置字体样式

    用遍历的方法对界面中控件设置字体样式,相关博文:http://www.cnblogs.com/tianzhijiexian/p/3900283.html

    Android视图控件架构分析之View、ViewGroup

    在Android中,视图控件大致被...Android控件树:   AndroidUI界面架构图:   一.测量View的工具类:MeasureSpec 1.MeasureSpec包含了测量的模式和测量的大小,通过MeasureSpec.getMode()获取测量模式,通过MeasureSp

    Android代码-BorePlugin

    ENGLISH README ...插件会自动遍历布局列出所有带id的控件,你可以在弹出的对话框中选择需要自动生成的控件 弹出的对话框中还可以勾选是否生成ViewHolder 选择好后Confirm确认即可 用法截图 代码

    java7源码-android:安卓

    小王子是针对Android手机研发的一套自动化测试工具,可对用户的点击操作进行录制并回放,同时,还可对手机进行基于Monkey原理的压力测试,针对某一款app进行控件遍历测试,埋点统计,接口测试等,此外,还可以对手机...

    基于Java的Android应用程序开发-24点游戏源码+详细项目说明.zip

    还学习了android的一些基本组件,例如:id,控件的唯一表示符,在同一个XML文件中不可重复,相当于身份证的作用,课用来寻找并且绑定此控件;layout_width以及layout_height,分别设置view的宽高;gravity指定当文本...

    android群雄传

    第3章 Android控件架构与自定义控件详解 32 3.1 Android控件架构 33 3.2 View的测量 34 3.3 View的绘制 37 3.4 View Group的测量 38 3.5 View Group的绘制 39 3.6 自定义View 39 3.6.1 对现有控件进行拓展 40...

    Android自定义View的使用及其原理知识点总结

    在Android开发中,系统提供给我们的UI控件是有限的,当我们需要使用一些特殊的控件的时候,只靠系统提供的控件,可能无法达到我们想要的效果,这时,就需要我们自定义一些控件,来完成我们想要的效果了。下面,我...

    uiautomator教程

    详细描述android测试工具 Uiautomator 使用方法和教程,附例子

    Android 仿京东搜索历史之自定义ViewGroup

    onMesure方法是计算当前控件摆放子view后的总高度,我们的例子中计算高度的逻辑为,遍历子view,然后子view的宽度一直累加,如果子view的累加宽度大于viewgroup的总宽度,那么就应该把上一个子view换行显

    Android 倒计时实现源码.zip

    2、每一秒,通过一个Handler去循环遍历,对每一条去刷新一次时间控件? 3、还是大家有其它的想法。   上述两种方案都不可取: 1、网络连接有时间差,况且数据访问量大的情况,服务器没法承受。 2、 循环遍历可行...

    Android 绘制多级树形选择列表实例代码

    一、概述 前段时间有个项目的需要在Android端...由于原始数据是树形结构的,我们需要先将树形结构转换为列表数据,类似根结点 – 父节点1 – 子结点1 – 子节点2 – 父节点2……这种形式 – 这恰恰是树的前序遍历  

    Appium_selenium_java_getListItem

    Appium_selenium_java: 获取处理android listview、ScrollView、recyclerview 等 list item控件下子元素遍历方法

    Android DigitalClock实现倒计时

    2、每一秒,通过一个Handler去循环遍历,对每一条去刷新一次时间控件? 3、还是大家有其它的想法。 上述两种方案都不可取: 1、网络连接有时间差,况且数据访问量大的情况,服务器没法承受。 2、 循环遍历可行,...

    Android自定义LinearLayout布局显示不完整的解决方法

    然而实现的时候:一共遍历了30条数据,却只显示了一条 断点查看代码:遍历addView()这个过程是正常的30次循环。那是布局的问题? 感觉没毛病。。。试着在自定义布局外层再加一层LinearLayout垂直方向,wrap_...

    Android自定义View实现绘制虚线的方法详解

    最简单的方法是利用ShapeDrawable,比如说你想用虚线要隔开两个控件,就可以在这两个控件中加个View,然后给它个虚线背景。 嗯,理论上就是这样子的,实现上也很简单。 &lt;!-- drawable 文件 --&gt; &lt;?xml ...

    Autox.js v6-v6.3.7

    更专业&强大的选择器API,提供对屏幕上的控件的寻找、遍历、获取信息、操作等。类似于Google的UI测试框架UiAutomator,您也可以把他当做移动版UI测试框架使用 采用JavaScript为脚本语言,并支持代码补全、变量重命名...

    本地音乐播放器Demo

    用工作线程去遍历外部存储,将找到的mp3文件信息保存到list集合中,用listview控件显示歌曲信息

    iTestin自动化测试录制脚本工具part2

    3、完善控件录制功能,修复某些应用引导界面无法正常识别控件的问题 4、完善控件录制功能,使客户端画面与终端实际画面保存同步 5、完善控件回放功能,使回放结果检查更准确 6、优化提交脚本界面和云测试界面分别...

    iTestin自动化APP脚本录制工具part1

    3、完善控件录制功能,修复某些应用引导界面无法正常识别控件的问题 4、完善控件录制功能,使客户端画面与终端实际画面保存同步 5、完善控件回放功能,使回放结果检查更准确 6、优化提交脚本界面和云测试界面分别...

Global site tag (gtag.js) - Google Analytics