android 在Button 的onDraw中加上invalidate()会导致背景缩放失败

来源:互联网 发布:苍穹软件使用教程 编辑:程序博客网 时间:2024/05/19 06:18

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();}




0 0
原创粉丝点击