(只能獲取當前可見的子元素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