Android基于Path的addRoundRect,Canvas剪切clipPath简洁的圆形图实现,Kotlin(2)
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageViewclass MyView : AppCompatImageView {private var mRadius = 0f //半径private val mPath = Path()constructor(ctx: Context, attributeSet: AttributeSet) : super(ctx, attributeSet) {val mBmpSrc = BitmapFactory.decodeResource(resources, R.mipmap.pic, null)setImageBitmap(mBmpSrc)}override fun onDraw(canvas: Canvas) {canvas.save()val w = measuredWidth.toFloat()val h = measuredHeight.toFloat()val mini = Math.min(w, h)mRadius = mini / 2fval left = (w - mini) / 2fval top = (h - mini) / 2fval right = (w + mini) / 2fval bottom = (h + mini) / 2fmPath.addRoundRect(left, top, right, bottom, mRadius, mRadius, Path.Direction.CW)canvas.clipPath(mPath)super.onDraw(canvas)canvas.restore()}
}
Android基于Path的addRoundRect,Canvas剪切clipPath简洁的圆角矩形实现,Kotlin(1)-CSDN博客文章浏览阅读850次,点赞12次,收藏8次。Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案RoundedBitmapDrawable是Android在support v4的扩展包中新增的实现圆角图形的关键类,借助RoundedBitmapDrawable的帮助,可以轻松的以Android标准方式实现圆角图形图象。头像有标准的四方形,也有圆形(如QQ)。Android水平渐变色圆角矩形一个Android水平渐变色圆角矩形,如图:其实实现很简单,主要感觉颜色渐变,圆角弧度比较漂亮,故记录下来。https://blog.csdn.net/zhangphil/article/details/144586015