首先这个图形的background需要是shape文件,然后在ViewHolder里面声明且绑定,。
e.g
public class ViewHolder {
public final ImageView 你的控件名;
public final View root;
public ViewHolder(View root) {
ivOvalSquare = (ImageView) root.findViewById(R.id.控件id);
this.root = root;
}
}
在Adapter的getView方法中,作如下编码:
//修改大小
ViewGroup.LayoutParams para = viewHolder.你的控件名.getLayoutParams();
para.height = 20;
para.width = 20;
viewHolder.ivOvalSquare.setLayoutParams(para);
//修改边距
// ((ViewGroup.MarginLayoutParams)viewHolder.你的控件名.getLayoutParams()).setMargins(0,0,0,0); //参数依次为 左上右下 边距
((ViewGroup.MarginLayoutParams)viewHolder.你的控件名.getLayoutParams()).leftMargin = 38;//左边距
//修改填充颜色
viewHolder.你的控件名.setBackgroundResource(R.drawable.square);
GradientDrawable gradientDrawable = (GradientDrawable) viewHolder.你的控件名.getBackground();
gradientDrawable.setColor(Color.parseColor(“#ffaaaa”));//填充粉色