android 在Button 的onDraw中加上invalidate()会导致背景缩放失败,如果需要不断刷新则需要手动设置背景大小
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
if(getBackground()!=null)
{
background=getBackground(); setBackground(null);
}
background.setBounds(0, 0, getWidth(), getHeight());
Bitmap bitmap= drawableToBitmap(background);
Matrix matrix=new Matrix();
matrix.postScale(getWidth()*1.0f/background.getIntrinsicWidth(),getHeight()*1.0f/background.getIntrinsicHeight());
Bitmap scaledBitmap=Bitmap.createBitmap(bitmap, 0, 0, background.getIntrinsicWidth(), background.getIntrinsicHeight(),matrix,true);
canvas.drawBitmap(scaledBitmap, 0, 0, paint);
invalidate();
}