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

相关推荐
恋猫de小郭1 小时前
再次紧急修复,Flutter 针对 WebView 无法点击问题增加新的快速修复
android·前端·flutter
李慕婉学姐1 小时前
【开题答辩过程】以《基于Android的健康助手APP的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看
android·java·mysql
似霰4 小时前
传统 Hal 开发笔记6----App 访问硬件服务
android·framework·hal
爱装代码的小瓶子4 小时前
【c++知识铺子】封装map和set(详细版)
android·java·c++
私人珍藏库4 小时前
AutoGLM无需豆包手机,让AI自动帮你点外卖-刷视频
android·ai·智能手机·工具·软件·辅助·autoglm
孤舟簔笠翁5 小时前
【Android驱动14】Android系统Crash工具使用方法和分析
android
帅得不敢出门6 小时前
MTK Android11 APP调用OTA升级
android·java·开发语言·framework
2501_915909066 小时前
苹果应用加密方案的一种方法,在没有源码的前提下,如何处理 IPA 的安全问题
android·安全·ios·小程序·uni-app·iphone·webview
用户2018792831676 小时前
Android App 换肤原理:用 "装修小房子" 故事浅谈
android