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网格布局实现--recyclerview
  2. Android: ViewPager and Fragments
  3. Android(安卓)代码混淆异常 transformClassesAndResourcesWithPr
  4. Android动态刷新listview中的数据
  5. android 异步图片处理 工具类
  6. android中隐藏以及显示软键盘代码
  7. Android(安卓)Spinner控件的简单应用
  8. 调用android系统自带功能
  9. 关于android的des算法代码

随机推荐

  1. 在android应用市场中直接定位到自己的应
  2. Android 去除头部标题栏
  3. Android -- Context(Application的应用)
  4. Android中启动Activity(startActivity)流
  5. Android 调试桥 ADB命令
  6. android wear-Drawing Watch Faces
  7. Free Android UI library & component ro
  8. [转]android颜色对应的xml配置值
  9. Android SDK r23
  10. ListView实用参数