Android基于Path的addRoundRect,Canvas剪切clipPath简洁的圆角矩形实现,Kotlin(1)

Android基于Path的addRoundRect,Canvas剪切clipPath简洁的圆角矩形实现,Kotlin(1)

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">>

    <com.myapp.MyView
        android:id="@+id/miv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white" />

</LinearLayout>
Kotlin 复制代码
import android.content.Context
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Path
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView


class MyView : AppCompatImageView {
    private var mRadius = 100f //半径
    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()

        mPath.addRoundRect(0f, 0f, measuredWidth.toFloat(), measuredHeight.toFloat(), mRadius, mRadius, Path.Direction.CW)
        canvas.clipPath(mPath)

        super.onDraw(canvas)
        canvas.restore()
    }
}

Android水平渐变色圆角矩形_android 渐变矩形-CSDN博客文章浏览阅读5.5k次。Android水平渐变色圆角矩形一个Android水平渐变色圆角矩形,如图:其实实现很简单,主要感觉颜色渐变,圆角弧度比较漂亮,故记录下来。xml代码:<?xml version="1.0" encoding="utf-8"?><shape ="http://schemas.android.com/apk/res/android" androi..._android 渐变矩形https://blog.csdn.net/zhangphil/article/details/80342159Android标准Glide加载圆形图和圆角矩形图_android glide加载圆角-CSDN博客文章浏览阅读1.4w次,点赞2次,收藏13次。引入: implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'https://blog.csdn.net/zhangphil/article/details/89336265Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案-CSDN博客文章浏览阅读4.4k次。Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案RoundedBitmapDrawable是Android在support v4的扩展包中新增的实现圆角图形的关键类,借助RoundedBitmapDrawable的帮助,可以轻松的以Android标准方式实现圆角图形图象。写一个简单的例子。写一个线性布局,竖直方向放三个Im_android roundedbitmapdrawablehttps://blog.csdn.net/zhangphil/article/details/51829650

Android圆形头像图Circle ImageView_android 圆形头像-CSDN博客文章浏览阅读8.9k次。《Android圆形头像图Circle ImageView》需要处理的原始图(pic):使用CircleImageView处理后的图(作为头像):现在很多的应用都有设置头像的功能,如QQ、微信、微博等。头像有标准的四方形,也有圆形(如QQ)。现在结合他人的代码加以修改,给出一个以原始图形中心为原点,修剪图片为头像的工具类,此类可以直接在布局文件中加载使用,比_android 圆形头像https://blog.csdn.net/zhangphil/article/details/44960551Android CircleImageView圆形ImageView-CSDN博客文章浏览阅读2.3w次,点赞5次,收藏11次。Android CircleImageView圆形ImageViewCircleImageView是github上一个第三方开源的实现圆形ImageView的项目。其在github上的项目主页是:https://github.com/hdodenhof/CircleImageView 实现的结果如图:重点说一说CircleImageView和附录文章1的异同,在开发中如何在特定情况下该选择何种_android circleimageviewhttps://blog.csdn.net/zhangphil/article/details/52130212

相关推荐
CYRUS_STUDIO2 小时前
利用 Linux 信号机制(SIGTRAP)实现 Android 下的反调试
android·安全·逆向
CYRUS_STUDIO2 小时前
Android 反调试攻防实战:多重检测手段解析与内核级绕过方案
android·操作系统·逆向
黄林晴6 小时前
如何判断手机是否是纯血鸿蒙系统
android
火柴就是我6 小时前
flutter 之真手势冲突处理
android·flutter
法的空间6 小时前
Flutter JsonToDart 支持 JsonSchema
android·flutter·ios
循环不息优化不止6 小时前
深入解析安卓 Handle 机制
android
恋猫de小郭6 小时前
Android 将强制应用使用主题图标,你怎么看?
android·前端·flutter
jctech7 小时前
这才是2025年的插件化!ComboLite 2.0:为Compose开发者带来极致“爽”感
android·开源
用户2018792831677 小时前
为何Handler的postDelayed不适合精准定时任务?
android
叽哥7 小时前
Kotlin学习第 8 课:Kotlin 进阶特性:简化代码与提升效率
android·java·kotlin