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

相关推荐
2501_916008899 分钟前
手机抓包app大全:无需root的安卓抓包软件列表
android·ios·智能手机·小程序·uni-app·iphone·webview
百锦再23 分钟前
第18章 高级特征
android·java·开发语言·后端·python·rust·django
gcygeeker1 小时前
安卓 4.4.2 电视盒子 ADB 设置应用开机自启动
android·adb·电视盒子
小驰行动派1 小时前
安卓上的极简番茄钟 | 开源
android·开源
jzlhll1231 小时前
android抽屉DrawerLayout在2025的沉浸式兼容
android
基哥的奋斗历程2 小时前
Kotlin_Flow_完整使用指南
android·开发语言·kotlin
j***82702 小时前
【玩转全栈】----Django连接MySQL
android·mysql·django
雨白3 小时前
深入理解 Android DocumentFile:性能陷阱与最佳实践
android
inputA3 小时前
【LwIP源码学习8】netbuf源码分析
android·c语言·笔记·嵌入式硬件·学习
CHINAHEAO3 小时前
FlyEnv+Bagisto安装遇到的一些问题
android