(只能获取当前可见的子元素view)
int firstVisableIndex = listView.getFirstVisiblePosition();
int index = busstations.indexOf(targetStation); //获取目标元素targetStation在list(busstations)中的索引位置TextView tempView = (TextView)(listView.getChildAt(index - firstVisableIndex));//(index - firstVisableIndex为目标元素targetStation在当前可见views中的索引位置
setCompoundDrawables使用:
Drawable drawable = getResources().getDrawable(R.drawable.clock);
drawable.setBounds(0, 0, textView.getHeight(), textView.getHeight());//后两个参数为图标的高宽
textView.setCompoundDrawables( null,null, drawable, null);//设置右图标
//隐藏右图标
Drawable drawable = getResources().getDrawable(R.drawable.clock);
drawable.setBounds(0, 0, 0, 0);
textView.setCompoundDrawables( null,null, drawable, null);
text1.setCompoundDrawables( null,null, drawable, null);
在oncreate中取view.textView.getHeight()为0:
据说是在此方法调用完成前,view还没有被绘制,因而取不到height