我有listview
,其中包含动态数量的项目。我正在尝试获取焦点项目,以便相应地定位imageView
。
以下是定位适用于按钮的示例:
button1 = (Button) findViewById(R.id.button1);
final ImageView arrow = (ImageView)findViewById(R.id.arrow);
final ImageView arrow1 = (ImageView)findViewById(R.id.arrow_1);
button1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
RelativeLayout.LayoutParams rlParams;
rlParams = new RelativeLayout.LayoutParams(
(int)RelativeLayout.LayoutParams.WRAP_CONTENT, (int)RelativeLayout.LayoutParams.WRAP_CONTENT);
rlParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.Button1);
rlParams.setMargins(0,0,0,5);
arrow.setLayoutParams(rlParams);
RelativeLayout.LayoutParams rlParams1;
rlParams1 = new RelativeLayout.LayoutParams(
(int)RelativeLayout.LayoutParams.WRAP_CONTENT, (int)RelativeLayout.LayoutParams.WRAP_CONTENT);
rlParams1.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.Button1);
rlParams1.addRule(RelativeLayout.RIGHT_OF,R.id.Button1);
rlParams1.setMargins(10,0,0,5);
arrow1.setLayoutParams(rlParams1);
}
});
和其他按钮一样。
问题是,使用方法我必须指定视图的id,如下一行所示:
rlParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.Button1);
所以我的问题是,如何在listview
项目上执行此操作?因为我没有每个项目的ID。