我创建了扩展视图类RoundIcon和类包含setIconImage()方法:
public void setIconImage(int imageFromResources) {
iconImage = BitmapFactory.decodeResource(getResources(), imageFromResources);
iconWidth = iconImage.getWidth();
iconHeight = iconImage.getHeight();
refreshDrawableState();
}
并有一个方法的onDraw():
@Override
protected void onDraw(Canvas canvas) {
if(px == 0 || py == 0)
{
px = 50;
py = 50;
}
canvas.drawCircle(px, py, circleRadius, circlePaint);
canvas.save();
if(iconImage != null)
{
int cardinalX = px - iconWidth/2;
int cardinalY = py - iconHeight/2;
canvas.drawBitmap(iconImage, cardinalX, cardinalY, iconPaint);
}
canvas.restore();
}
问题是,该函数的onDraw()不每次执行该方法setIconImage()被从主叫活动,因此图标不会在用户界面中而改变。
有谁知道如何修改代码,以便每次方法setIconImage被调用时重绘的图像?