1.設(shè)置paint抗鋸齒
val bgPaint = Paint().apply {
isAntiAlias = true //抗鋸齒
isDither = true //防抖動(dòng)
isFilterBitmap = true //bitmap抗鋸齒
}
2.設(shè)置canvas抗鋸齒
在
override fun onDraw(canvas: Canvas) {}
或者
override fun dispatchDraw(canvas: Canvas) {}
中調(diào)用 canvas.drawFilter = paintFlagsDrawFilter
val paintFlagsDrawFilter = PaintFlagsDrawFilter(
0,
Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG
)
canvas.drawFilter = paintFlagsDrawFilter
3.關(guān)閉硬件加速
在View中調(diào)用
setLayerType(View.LAYER_TYPE_SOFTWARE, null) //關(guān)閉硬件加速
附上開(kāi)啟的代碼 myView.setLayerType(View.LAYER_TYPE_HARDWARE, null); //開(kāi)啟硬件加速