/**
* Created by Veyron on 2017/2/20.
* Function:自定义实现边缘凹凸卡卷效果
*/
public class CouponView extends LinearLayout {
private Paint mPaint; //画笔
private float gap = 8; //圆间距
private float radius = 10; //半径
private int circleNum; //圆数量
private float remain;
private float width; //视图宽
public CouponView(Context context) {
super(context);
}
public CouponView(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//设置是否使用抗锯齿功能,会消耗较大资源,绘制图形速度会变慢。
mPaint.setDither(true);//设定是否使用图像抖动处理,会使绘制出来的图片颜色更加平滑和饱满,图像更加清晰
mPaint.setColor(Color.WHITE);
mPaint.setStyle(Paint.Style.FILL);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
if (remain==0){
//计算不整除的剩余部分
remain = (int)(h-gap)%(2*radius+gap);
}
circleNum = (int) ((h-gap)/(2*radius+gap)); //计算圆的数量
}
public CouponView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* 上面定义了圆的半径和圆间距,同时初始化了这些值并且获取了需要画的圆数量。
接下来只需要一个一个将圆画出来就可以了。
* @param canvas
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//循环在左右两个边上画出凹凸效果
for (int i=0;i<circleNum;i++){
float y = gap+radius+remain/2+((gap+radius*2)*i);//计算出y轴坐标
canvas.drawCircle(0,y,radius,mPaint);//在左边边画圆
canvas.drawCircle(width,y,radius,mPaint);//在右边画圆
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="20dp"
android:paddingBottom="20dp">
<com.veyron.www.couponview.view.CouponView
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF5216"
android:padding="20dp">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/hanber"
android:scaleType="centerCrop"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26dp"
android:textColor="#000000"
android:text="优惠汉堡劵"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:padding="5dp"
android:text="编号:007"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:padding="5dp"
android:text="优惠价:¥18"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="截止日期:2017-06-09"
/>
</LinearLayout>
</com.veyron.www.couponview.view.CouponView>
</FrameLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有