SmoothCheckBox
SmoothCheckBox copied to clipboard
勾的绘制速度好慢
勾的绘制速度好慢,有没有什么办法加快呢
可修改line 283, line 311.
float step = (mWidth / 20.0f) < 3 ? 3 : (mWidth / 20.0f);
'step' 变量为控制单次绘制对勾的增量。需要注意,如果单次绘制的增量过大,会导致不够平滑。
不过这确实是设计上的一个缺陷,如果CheckBox宽高比较小的话,的确会绘制比较慢,这个我等不忙后改一下。你暂时可以用上面的解决方案。
一般checkbox都比较小,不会有明显的平滑问题,像我这边项目的checkbox在调试机上实际才56px,我改了代码分成5次绘制,效果好多了,一次绘制耗时10-20ms左右,5次不超过100ms,加上背景圆设置为200ms,一共不超过300ms,对于checkbox来说感觉比较能接受。
还有个小问题, if (mDrewDistance < mLeftLineDistance + mRightLineDistance) { postDelayed(new Runnable() { @Override public void run() { postInvalidate(); } }, 10); } 这里应该改成 if (mDrewDistance - step < mLeftLineDistance + mRightLineDistance) 不然会少了最后一次对勾的绘制,按下去的瞬间才绘制最后一次,又变长了一点点。
Sometimes will appeal the hook is incompleteness. And I make it to be. if (mDrewDistance - step < mLeftLineDistance + mRightLineDistance) .But some problems also appeal the postInvalidate exect all the time.