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

相关推荐
Digitally27 分钟前
如何用5种实用方法将电脑上的音乐传输到安卓手机
android·智能手机·电脑
HahaGiver6661 小时前
Unity与Android原生交互开发入门篇 - 打开Unity游戏的设置
android·unity·交互
2501_915909062 小时前
WebView 调试工具全解析,解决“看不见的移动端问题”
android·ios·小程序·https·uni-app·iphone·webview
IT乐手3 小时前
android 下载管理工具类
android
2501_915106324 小时前
App 怎么上架 iOS?从准备资料到开心上架(Appuploader)免 Mac 上传的完整实战流程指南
android·macos·ios·小程序·uni-app·iphone·webview
科技峰行者5 小时前
安卓16提前发布能否改写移动生态格局
android
蒲公英少年带我飞5 小时前
Android NDK 编译 protobuf
android
沐怡旸5 小时前
【底层机制】ART虚拟机深度解析:Android运行时的架构革命
android·面试
小禾青青6 小时前
uniapp安卓打包遇到报错:Uncaught SyntaxError: Invalid regular expression: /[\p{L}\p{N}]/
android·uni-app
studyForMokey6 小时前
【Kotlin内联函数】
android·开发语言·kotlin