先上图
样式主要是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>
微信关注 “安卓集中营”,获取更多
或者扫码关注
一起共同学习探讨