package com.example.ysmb.myapplication;import android.content.Context;import android.graphics.Canvas;import android.graphics.Path;import android.graphics.RectF;import android.graphics.Region;import android.util.AttributeSet;import android.widget.ImageView;/** * Created by YSMB on 2016/2/16. */public class RoundImageView extends ImageView {    private Path mPath;    public RoundImageView(Context context) {        super(context);        init(context);    }    public RoundImageView(Context context, AttributeSet attrs) {        super(context, attrs);        init(context);    }    public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        init(context);    }    private void init(Context context) {        mPath = new Path();    }    @Override    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {        super.onLayout(changed, left, top, right, bottom);    }    @Override    protected void onDraw(Canvas canvas) {        mPath.addRoundRect(new RectF(0, 0, getWidth(), getHeight()), 50, 50, Path.Direction.CW);        canvas.save();        canvas.clipPath(mPath);        //这一行代码是为了去掉底部两个圆角        canvas.clipRect(new RectF(0, getHeight() / 2, getWidth(), getHeight()), Region.Op.UNION);        super.onDraw(canvas);        canvas.restore();    }}

更多相关文章

  1. Android Camera子系统代码流程1
  2. 【Demo实例】Android FTP上传带进度条(优化后代码)
  3. android全屏设置代码
  4. Android中一些比较好的开源代码项目
  5. 【分享】大量android软件开发资料和实例代码【转】
  6. Eclipse Android 代码自动提示功能
  7. 【Android 应用开发】 Android 相关代码规范 更新中 ...
  8. Android开发常用代码片段(一)

随机推荐

  1. 零基础Android嵌入式开发视频教程
  2. Android(安卓)自定义主题和风格
  3. android studio version 2.3.3 打包签名V
  4. Android Framework ContentProvider框架
  5. Android开发笔记之adb参数指南
  6. Android 9.0 init 启动流程
  7. Android Studio 学习 - HelloWorld
  8. 转:Adapter 从源头开始适配!
  9. 单点登录(一)| LDAP 协议
  10. Android上传图片的方式