android中圆角图片(ImageView)
2014-03-04 16:29
239 查看
圆角图片没有生硬的感觉,带来很好的交互感觉,其为自定义代码实现方法,继承ImageView,实现过程如下:
[java] view
plaincopy
public class RoundImageView extends ImageView {
public RoundImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public RoundImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
/**
* RectF 圆角矩形
* **/
clipPath.addRoundRect(new RectF(0, 0, w, h), 4.0f, 4.0f,
Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
引用实现代码的布局如下:
[html] view
plaincopy
<com.test.RoundImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerCrop"
[java] view
plaincopy
public class RoundImageView extends ImageView {
public RoundImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public RoundImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
/**
* RectF 圆角矩形
* **/
clipPath.addRoundRect(new RectF(0, 0, w, h), 4.0f, 4.0f,
Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
引用实现代码的布局如下:
[html] view
plaincopy
<com.test.RoundImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerCrop"
相关文章推荐
- Android开发之自定义圆角矩形图片ImageView的实现
- Android开发之自定义圆角矩形图片ImageView的实现 - Jamy Cai
- Android 圆形、圆角图片ImageView
- Android自定义圆角ImageView 支持网络图片
- Android自定义ImageView实现图片圆形 ,椭圆和矩形圆角显示
- android ImageView网络图片加载、动态设置尺寸、圆角..
- Android开发之自定义圆角矩形图片ImageView的实现
- Android BitmapShader 实战 实现圆形、圆角图片(重写ImageView)
- SelectableRoundedImageView——Android图片圆角类库
- Android ImageView实现圆角,圆形图片
- Android Xfermode 实战 实现圆形、圆角图片(重写ImageView)
- Android自己定义圆角ImageView 支持网络图片
- 【Android CustomImageView】图片圆角设定/圆形图片设定
- Android自定义ImageView实现图片缩放滑动,双击放大缩小,多点触控旋转,圆角矩形,圆形和仿刮刮卡效果
- Android自定义圆角矩形图片ImageView
- Android Glide加载图片圆角效果与ImageView的ScaleType冲突问题
- android 如何重写imageview 让图片有圆角效果
- android中圆角图片(ImageView)
- Android imageView 自定义单个或多个角为圆角及圆形图片工具
- Android圆角图片轻量级CircleImageView