Android实现Imageview上面圆角下面直角效果
来源:互联网 发布:淘宝什么是权重 编辑:程序博客网 时间:2024/04/28 07:56
如图背景为四个角都是圆角的图片,我们完全可以使用shape写出四个圆角,包括描边 填充色等,代码如下:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 填充的颜色 --> <solid android:color="#EFEFEF" /> <!-- 设置按钮的四个角为弧形 --> <!-- android:radius 弧形的半径 --> <corners android:radius="5dip" /> <stroke android:width="0.1dp" android:color="#D8D8D8" /></shape>
solid为填充的颜色,stroke为描边颜色 corners为圆角弧度 ,以上代码便完成了 背景圆角的效果,可是如何实现imageview上面的两个直角变成圆角呢,这时候就需要我们自定义一个view继承自Imageview对Imageview的样式进行一定的修改
public class YuanJiaoImageView extends ImageView { //圆角弧度 private float[] rids = {10.0f,10.0f,10.0f,10.0f,0.0f,0.0f,0.0f,0.0f,}; public YuanJiaoImageView(Context context) { super(context); } public YuanJiaoImageView(Context context, AttributeSet attrs) { super(context, attrs); } public YuanJiaoImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } protected void onDraw(Canvas canvas) { Path path = new Path(); int w = this.getWidth(); int h = this.getHeight(); //绘制圆角imageview path.addRoundRect(new RectF(0,0,w,h),rids,Path.Direction.CW); canvas.clipPath(path); super.onDraw(canvas); }}下面是关于drawRoundRect方法的用法
阅读全文
1 0
- Android实现Imageview上面圆角下面直角效果
- android上面圆角,下面直角 ImageView
- 安卓imageview实现上面两个圆角下面两个直角的效果
- Android 自定义上面圆角下面直角的ImageView
- android ImageView实现上面圆角下面直角(xml实现方法)
- android ImageView实现上面圆角下面直角(自定义view实现)
- 安卓自定义上面圆角下面直角的RoundCornerImageView
- 设置Button按钮上面圆角下面直角
- Imageview上边圆角,下边直角
- Android实现button一边圆角一边直角
- Android实现button一边圆角一边直角
- android ImageView实现变暗效果
- android ImageView实现变暗效果
- android ImageView实现变暗效果
- 实现Imageview两个圆角的效果
- Android--在显示ImageView时图片上面和下面都出现一段空白区间的解决办法
- 【Android】在显示ImageView时图片上面和下面都出现一段空白区间的解决办法
- Android实现圆角ImageView
- linux分区满了,如何进行扩容
- php闭包函数的研究
- 基于RESTful风格的SpringMVC的测试:MockMVC
- 【Jquery学习】第四部分
- 关于QT UDP组播的两个问题
- Android实现Imageview上面圆角下面直角效果
- FragmentDialog 代码
- Activity生命周期
- 如何用Maven创建web项目(具体步骤)
- Effective c++ 学习笔记(七)
- 【剑指offer】题10:二进制中1的个数
- axios中post请求出错,由于content-type引起的跨域的解决方法
- CSS3的@keyframes用法详解:
- Hibernate Criteria指定返回列