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

相关推荐
doublelixin4 小时前
AOSP (Android11) 集成Google GMS三件套
android
xzkyd outpaper7 小时前
onSaveInstanceState() 和 ViewModel 在数据保存能力差异
android·计算机八股
梓仁沐白8 小时前
【Kotlin】协程
开发语言·python·kotlin
CYRUS STUDIO8 小时前
FART 脱壳某大厂 App + CodeItem 修复 dex + 反编译还原源码
android·安全·逆向·app加固·fart·脱壳
WAsbry8 小时前
现代 Android 开发自定义主题实战指南
android·kotlin·material design
xzkyd outpaper9 小时前
Android动态广播注册收发原理
android·计算机八股
唐墨1239 小时前
android与Qt类比
android·开发语言·qt
林林要一直努力10 小时前
Android Studio 向模拟器手机添加照片、视频、音乐
android·智能手机·android studio
AD钙奶-lalala10 小时前
Mac版本Android Studio配置LeetCode插件
android·ide·android studio
梓仁沐白11 小时前
【Kotlin】注解&反射&扩展
开发语言·python·kotlin