我能以某种方式从适配器或扩展 Activity 的类以外的类中获取视图的子类吗?
ImageView v = (ImageView)parent.getChildAt(position);
v.setImageResource(R.drawable.test2);
我需要更改 GridView 中的每个 ImageView,因为它们是动态下载的。
我的getView:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
if (DefinedValues.width/3 < DefinedValues.height/4)
imageView.setLayoutParams(new GridView.LayoutParams
(DefinedValues.height/4, DefinedValues.height/4));
else
imageView.setLayoutParams(new GridView.LayoutParams
(DefinedValues.width/3-5, DefinedValues.width/3-5));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(R.drawable.test3);
return imageView;
}