当前位置:网站首页>Customize the view to realize the background of redeeming lottery tickets [elementary]
Customize the view to realize the background of redeeming lottery tickets [elementary]
2022-07-25 09:44:00 【Happy play rabbit】

[ The core idea ]
- Inherit LinearLayout, Rewrite three constructors ( Concatenation constructor )
- Fixed mode , Rewrite custom view Three methods to be implemented
###[ The core code is as follows ]
public class LotteryView extends LinearLayout{
private Paint mPaint;
private float mRadious =6; // radius
private float mGap =5; // Gap of edge serration
private int mCircleNumX; // The transverse Number of edge serrated circles
private int mCircleNumY; // The longitudinal Number of edge serrated circles
public LotteryView(Context context) {
super(context);
}
public LotteryView(Context context, AttributeSet attrs) {
super(context, attrs);
//1. Brush initialization
mPaint = new Paint();
mPaint.setDither(true);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(Color.WHITE);
}
public LotteryView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
//2. Specify the number of edge aliases drawn
mCircleNumX=(int)((w-mGap)/(mRadious*2+mGap));
mCircleNumY=(int)((h-mGap)/(mRadious*2+mGap));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//3. Specify the position of each circle center and draw a circle and fill the middle rectangle
for (int i = 0; i <mCircleNumX ; i++) {
float radiousX=mGap+mRadious+((mRadious*2+mGap)*i);
float radiousY=mGap+mRadious+((mRadious*2+mGap)*i);
// Draw above
canvas.drawCircle(radiousX,0,mRadious,mPaint);
// Draw left side
canvas.drawCircle(0,radiousY,mRadious,mPaint);
// Draw the right
canvas.drawCircle(getWidth(),radiousY,mRadious,mPaint);
// Draw below
canvas.drawCircle(radiousX,getHeight(),mRadious,mPaint);
}
}
}
###[ Reference directly in the layout ]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="50dp" android:orientation="vertical" tools:context="com.jing.www.lotterydemo.MainActivity">
<com.jing.www.lotterydemo.LotteryView android:layout_width="match_parent" android:layout_height="150dp" android:background="#7E30B8DA" tools:ignore="MissingConstraints">
</com.jing.www.lotterydemo.LotteryView>
<com.jing.www.lotterydemo.LotteryView android:layout_width="match_parent" android:layout_height="150dp" android:background="#8A3CAC" tools:ignore="MissingConstraints">
</com.jing.www.lotterydemo.LotteryView>
<com.jing.www.lotterydemo.LotteryView android:layout_width="match_parent" android:layout_height="150dp" android:background="#59DB22" tools:ignore="MissingConstraints">
</com.jing.www.lotterydemo.LotteryView>
</LinearLayout>
###[Demo Address ]
https://github.com/EugeniaGao/LotteryDemo
Gentle little brother and beautiful little sister , Like to like a little ~
边栏推荐
- Redis list structure command
- Browser access to swagger failed with error err_ UNSAFE_ PORT
- Redis list 结构命令
- cf #785(div2) C. Palindrome Basis
- Indexes, views and transactions of MySQL
- uni-app小程序如何自定义标题内容(如何解决小程序标题不居中)
- The shortest path problem Bellman Ford (single source shortest path) (illustration)
- Swift简单实现待办事项
- 【降维打击】希尔伯特曲线
- STM32+HC05串口蓝牙设计简易的蓝牙音箱
猜你喜欢

*6-1 CCF 2015-03-2 numerical sorting
![[gplt] 2022 popular lover (Floyd)](/img/30/c96306ca0a93f22598cec80edabd6b.png)
[gplt] 2022 popular lover (Floyd)

Install MySQL in Ubuntu and create new users

The jar package has been launched on Alibaba cloud server and the security group has been opened, but postman still can't run. What should we do

¥ 1-3 SWUST OJ 942: reverse sequence table

解决QTCreator使用VS编译中文乱码错误

服务器cuda toolkit多版本切换

@2-1 safety index predicted by CCF at the end of December 1, 2020

语音聊天app源码-钠斯网络源码出品

Kotlin collaboration: foundation and use of collaboration
随机推荐
*7-2 CCF 2015-09-2 date calculation
Redis string 结构命令
降低程序空间复杂度的一些技巧
初识Opencv4.X----为图像添加高斯噪声
关于C和OC
Flutter Rive 多状态例子
Kotlin realizes file download
UI——无限轮播图和分栏控制器
@3-2 optimal threshold of CCF 2020-12-2 final forecast
OC -- Foundation -- string + date and time
Swagger2显示get接口有问题,加注解就能解决
[code source] daily one question three paragraph
Raspberry sect door ban system based on face recognition
SurfaceView 闪屏(黑一下问题)
Flex layout syntax and use cases
Redis database foundation
laravel 调用第三方 发送邮件 (php)
一张图讲解 SQL Join 左连 又连
OC -- Foundation -- dictionary
[code source] daily question - queue