Android 优惠卷样式

先上图

样式主要是MyCardView

新建MyCardView降代码复制进去

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * @fileName MyCardView
 * @date on 2019-01-03 16:16
 * @developers czh
 * @email 1632365610@qq.com
 */
public class MyCardView  extends LinearLayout {
    //圆的半径
    private int radius = 8;
    //圆之间的间距
    private int gap = 8;
    private Paint mPaint;

    public MyCardView(Context context) {
        super(context);
        init();
    }

    public MyCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyCardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setDither(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //圆的个数
        int roundNum = getWidth() / (radius * 2 + gap * 2);
        for (int i = 1; i <= roundNum; i++) {
            canvas.drawCircle((gap + radius) * (2 * i - 1), 0, radius, mPaint);
            canvas.drawCircle((gap + radius) * (2 * i - 1), getHeight(), radius, mPaint);
        }
    }

}
布局源码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.gzzhsdcm.czh.zhihesdcmly.view.MyCardView
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_120"
        android:background="#5ED6FF"
        android:orientation="horizontal"
        android:padding="20dp">

        <TextView
            android:id="@+id/tv_yhj_dazhe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="¥100"
            android:textColor="#ffffff"
            android:textSize="30dp" />

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:background="#888888" />

        <LinearLayout
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <com.gzzhsdcm.czh.zhihesdcmly.view.AdaptionSizeTextView
                android:id="@+id/tv_yhj_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="满2000减100"
                android:textColor="#90000000"
                android:textSize="16dp" />

            <com.gzzhsdcm.czh.zhihesdcmly.view.AdaptionSizeTextView
                android:id="@+id/tv_yhj_desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="· 满188元可用"
                android:textColor="#80000000"
                android:textSize="12dp" />

            <com.gzzhsdcm.czh.zhihesdcmly.view.AdaptionSizeTextView
                android:id="@+id/tv_yhj_xl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="· 限领1份"
                android:textColor="#80000000"
                android:textSize="12dp" />

            <com.gzzhsdcm.czh.zhihesdcmly.view.AdaptionSizeTextView
                android:id="@+id/tv_yhj_yxq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="· 2016-08-29 - 2016-08-31"
                android:textColor="#80000000"
                android:textSize="12dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_gravity="center"
            >

            <com.gzzhsdcm.czh.zhihesdcmly.view.AdaptionSizeTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="立即领取"
                android:textSize="@dimen/size_16"
                android:textColor="#ff00"
                />
        </LinearLayout>

    </com.gzzhsdcm.czh.zhihesdcmly.view.MyCardView>

</android.support.constraint.ConstraintLayout>

微信关注 “安卓集中营”,获取更多

或者扫码关注

一起共同学习探讨

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值