1. 自定义大转盘
    写一个.class文件,布局里面用包名点到就可以了.
    简易的效果

  2. 布局

    <jt.com.fan.FanViewandroid:id="@+id/fanView"android:layout_width="match_parent"android:layout_height="match_parent" />
    
  3. MyClass( 自定义类 )

package jt.com.fan;import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;import java.util.ArrayList;public class FanView extends View implements View.OnClickListener {private Paint mFanPaint , mTextPaint ;private ArrayList<Fan> mFanList = new ArrayList<Fan>();private RotateAnimation mRotateAnimation;//控件旋转动画private boolean isStartAnim;//是否已经启动了动画public FanView(Context context) {super(context);init();}public FanView(Context context,   AttributeSet attrs) {super(context, attrs);init();}public FanView(Context context,   AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}private void init() {//初始化//画笔mFanPaint = new Paint();mFanPaint.setStyle(Paint.Style.FILL);//扇形中的文字mTextPaint = new Paint();mTextPaint.setTextSize(60);//单击事件setOnClickListener(this);}public void addFan(Fan fan){//添加bean对象mFanList.add(fan);//初始化invalidate();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);//定义矩形区域用于画环形,圆,椭圆;RectF rectF = new RectF();rectF.left = 0 ;rectF.top = 0;rectF.right = 600;rectF.bottom = 600 ;//fori循环画扇形for (int i = 0; i < mFanList.size(); i++) {Fan fan = mFanList.get(i);//扇形*****颜色mFanPaint.setColor(fan.getColor());//画扇形canvas.drawArc(rectF,fan.getStartAngle(),360/mFanList.size(),true,mFanPaint);//文字画到扇形Path path = new Path();//定义文字区域,需要传入开始角度和结束角度path.addArc(rectF,fan.getStartAngle(),360/mFanList.size());mTextPaint.setColor(Color.BLACK);//沿路径path画文字,第一个参数是文字,第二个参数是路径,// 第三个参数是水平距离,也就是扇形的起点边界//第四个参数是纵向距离canvas.drawTextOnPath(fan.getName(),path,90,60,mTextPaint);}mFanPaint.setColor(Color.WHITE);//我把中间图片为白色canvas.drawCircle(300,300,150,mFanPaint);mTextPaint.setColor(Color.BLACK);//我把字体为黑色canvas.drawText("sssss",300-mTextPaint.measureText("Start")/2,300+mTextPaint.getTextSize()/2,mTextPaint);//画中间文字}@Overridepublic void onClick(View v) {if (isStartAnim){this.clearAnimation();//清除动画mRotateAnimation = new RotateAnimation(0,(int)(360*Math.random()),300,300);mRotateAnimation.setDuration(100);//动画时间mRotateAnimation.setRepeatCount(0);//重复次数mRotateAnimation.setFillEnabled(true);//动画执行保留目前的状态mRotateAnimation.setFillAfter(true);//动画执行结束保留目前的状态startAnimation(mRotateAnimation);//开启isStartAnim =false;//设置变量根据(if条件判断)}else{mRotateAnimation = new RotateAnimation(0,360,300,300);mRotateAnimation.setDuration(1000);//动画时间mRotateAnimation.setRepeatCount(-1);//重复次数mRotateAnimation.setInterpolator(new LinearInterpolator());//差速器:匀速执行startAnimation(mRotateAnimation);//开启isStartAnim = true;//设置变量根据(if条件判断)}}
}
  1. MyBean(看情况 我写的是开始角度,扇形上的文字,以及扇形颜色)
package jt.com.fan;public class Fan {//开始角度int startAngle;//扇形的名字(显示于扇形中的文字)String name;//颜色int color;//set/get方法public Fan(int startAngle, String name, int color) {this.startAngle = startAngle;this.name = name;this.color = color;}public int getStartAngle() {return startAngle;}public void setStartAngle(int startAngle) {this.startAngle = startAngle;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getColor() {return color;}public void setColor(int color) {this.color = color;}
}
  1. 效果实现

自定义大转盘(简陋版)相关推荐

  1. android自定义大转盘,Android 自定义View 抽奖大转盘(1)

    站在别人的肩膀上慢慢前行 只是部分的转盘主要功能的实现,其他的东西可以慢慢填上,这里做一个简单的介绍 镇楼图 S71010-17315559.jpg github链接 https://github.c ...

  2. asp大转盘抽奖程序代码微信大转盘asp版源码

    昨天接到一个客户需求让帮忙找个asp的微信大转盘代码,我找遍全网也没找到有asp做的微信大转盘,网上基本上全是php做的大转盘,没办法受客户所托,昨晚给写了一个asp大转盘代码程序,后台设置奖项,每天 ...

  3. android自定义大转盘,android 代码绘制转盘抽奖的实现

    android 代码绘制转盘抽奖的实现 先上图 第一个是 整体的布局 xmlns:tools="http://schemas.android.com/tools" android: ...

  4. vue3自定义大转盘抽奖

    先看看需求: 不抽奖的情况下转盘默认会转(插件不支持这个功能) 再看看这套模板(布局已经弄好,找ui切图微调即可) 一.搞个文件夹丢进去 copy全部 <!--* new page* @auth ...

  5. uni-app - 九宫格老虎机抽奖机插件源码(支持服务端API接口控制最终中奖的奖品,自定义组件可随意配置和控制,带组件文档轻松 DIY 自己的营销页抽奖机)幸运抽奖圆形大转盘插件组件

    前言 如果您需要圆形大转盘抽奖机(如下图所示),请访问:这篇文章. 关于九宫格式老虎机宫格跳动抽奖,网上的大部分源码非常乱且无注释,根本无法改造, 本文提供的组件源码,代码干净整洁注释详细,并且配备超 ...

  6. uni-app - 幸运抽奖圆形大转盘插件组件(支持后端接口确定最终奖品,可自定义轮盘宽高、颜色、字号、按钮等等,全端兼容代码干净整洁无 BUG,官方最好用的营销页面抽奖转盘源码)老虎机九宫格式抽奖机

    前言 如果您需要九宫格式抽奖机(如下图所示) ,请访问:这篇文章. 网上很多文章都非常乱且一堆 BUG,本文提供无 BUG 的 "组件式" 抽奖大转盘, 您只需要复制粘贴,按照组件 ...

  7. android自定义抽奖,Android 自定义View 抽奖大转盘(2)

    这是转盘的第二个版本,添加了外围的圆圈 第一个demo在这儿可以找到 镇楼图 S171011-11370203.jpg 项目的本来来源来自于 添加外围的圆圈,主要由两部分组成 1.画小圆.2.圆盘位置 ...

  8. 免费三加一php源码,最新微联运微信投票独立版PHP源码|基于31CMS投票系统二次开发+幸运大转盘+独立后台吸粉工具...

    源码介绍 投票系统对于微信公众号来说是一种非常有效的吸粉手段!!微信投票系统是基于网络的一种投票收集及统计的系统,比传统的投票统计更为方便.快速.准确.投票的同时 ,会有更多的朋友关注你,朋友的好友通 ...

  9. 微信公众号大转盘抽奖活动链接怎么添加

    很多微信公众号都会有抽奖活动,想要给自己的公众号添加大转盘抽奖活动的链接,希望可以帮助大家在微信公众号中举办起抽奖活动,活跃起自己的粉丝,该怎么添加呢?下面我们就来看看详细的教程. 微信公众号大转盘抽 ...

最新文章

  1. [导入][转]常用CSS缩写语法总结
  2. 用c语言编程实现strcpy,用c语言.模拟实现strcpy,strcat,strcat,memcpy,memmove
  3. Linux提权CVE-2022-0847分析
  4. SQL基础【十八、事物】(sql事物慎用,还是写业务逻辑代码好一些,入伙涉及到更换数据啥的很麻烦!)
  5. Mysql日期和时间函数大全
  6. fedora12下pppoe服务器的搭建
  7. oracle中dbms_如何在DBMS中找到关系的最高范式?
  8. 解决exe文件在别人电脑上运行缺失文件情况
  9. RecyclerView通过notifyItemChanged方法更新item数据避免闪烁
  10. Mysql查询为空赋值为0
  11. 解决精简版的XP下,无法使用运程桌面
  12. c语言实验报告1.4.3,c语言实验报告实验三.doc
  13. 面试题:Redis 40 道
  14. PyQt5_pyqtgraph股票MACD指标
  15. VS2010:X64和X86冲突问题
  16. Java hashCode详解
  17. 曙光服务器amd芯片,AMD六核体验 曙光Ar-H服务器首发评测.docx
  18. 给计算机系学生的建议
  19. js中的隐式类型转换有哪些
  20. lrs_save_searched_string

热门文章

  1. PdfFactory.v4.64.Pro Server 和 FinePrint-v7.04-Pro Server + keygen
  2. excel文件外链多了打开慢怎么办
  3. 写了一个适配 Android12-exported 的小插件
  4. 判断是否为移动端或浏览器
  5. Java匹马行天下之JavaWeb核心技术——Servlet
  6. ansible 高级用法
  7. backgroundWorker学习
  8. CodeBlocks 安装教程(百度网盘)
  9. MYSQL EXPLAIN 工具
  10. 用原生安卓 做一个“套壳”APP、混合开发、安卓H5加壳开发