当前位置: 首页 > 编程日记 > 正文

Android 自定义View之3D骰子旋转

你可以指定立方体中每一面骰子的点数,颜色和背景,同时也可以指定执行的动画时间和动画插值器

更多有趣的view


使用

在根目录的build.gradle添加这一句代码:

allprojects {repositories {//...maven { url 'https://jitpack.io' }}
}
复制代码

在app目录下的build.gradle添加依赖使用:

dependencies {implementation 'com.github.samlss:DiceLoadingView:1.0'
}复制代码

在开始介绍DiceLoadingView之前,先看一下骰子即DeiceView的组成

DiceView

在DiceLoadingView中应用的骰子view

以下为效果图:

使用

布局中:

<com.iigo.library.DiceViewandroid:layout_marginTop="10dp"app:number="one"app:bgColor="@android:color/white"app:borderColor="@color/colorPrimary"app:pointColor="@color/colorPrimary"android:layout_width="50dp"android:layout_height="50dp" />
复制代码

代码:

diceView.setNumber(2); //设置骰子点数,必须为1-6
diceView.setPointColor(Color.RED); //设置点的颜色
diceView.setBgColor(Color.RED); //设置背景颜色
diceView.setBorderColor(Color.RED); //设置边界颜色
复制代码

属性说明:

开始描述效果图之前,先看一张说明图:

attrdescription
number骰子点数 one(1), two(2), three(3), four(4), five(5), six(6)
pointColor点的颜色
bgColor背景颜色
borderColor边界颜色

DiceLoadingView

使用

布局中使用:

 <com.iigo.library.DiceLoadingViewandroid:id="@+id/dlv_loading1"app:animDuration="2000"app:animInterpolator="AccelerateDecelerateInterpolator"app:firstSideDiceNumber="1"app:firstSideDicePointColor="@color/colorPrimary"app:firstSideDiceBgColor="@android:color/white"app:firstSideDiceBorderColor="@color/colorPrimary"app:secondSideDiceNumber="2"app:secondSideDicePointColor="@android:color/holo_orange_dark"app:secondSideDiceBgColor="@android:color/white"app:secondSideDiceBorderColor="@android:color/holo_orange_dark"app:thirdSideDiceNumber="3"app:thirdSideDicePointColor="@android:color/holo_red_dark"app:thirdSideDiceBgColor="@android:color/white"app:thirdSideDiceBorderColor="@android:color/holo_red_dark"app:fourthSideDiceNumber="4"app:fourthSideDiceBgColor="@android:color/white"app:fourthSideDiceBorderColor="@android:color/holo_green_dark"app:fourthSideDicePointColor="@android:color/holo_green_dark"android:layout_width="50dp"android:layout_height="50dp" />复制代码

代码中使用:

diceLoadingView.start(); //开始动画
diceLoadingView.stop(); //停止动画
diceLoadingView.pause(); //暂停动画
diceLoadingView.resume(); //恢复动画
diceLoadingView.release(); //不需要使用该loading view的时候可手动释放,例如在activity的ondestroy()中diceLoadingView.setDuration(3000); //设置动画时间
diceLoadingView.setInterpolator(new AnticipateOvershootInterpolator()); //设置动画插值器
diceLoadingView.setFirstSideDiceNumber(2); //设置第一面骰子点数(1-6)
diceLoadingView.setFirstSidePointColor(Color.parseColor("#FF7D81")); //设置第一面骰子点的颜色
diceLoadingView.setFirstSideDiceBgColor(Color.WHITE); //设置第一面骰子背景颜色
diceLoadingView.setFirstSideDiceBorderColor(Color.GRAY); //设置第一面骰子边界颜色diceLoadingView.setSecondSideDiceNumber(3); //设置第二面骰子点数(1-6)
diceLoadingView.setSecondSidePointColor(Color.BLUE); //设置第二面骰子点的颜色
diceLoadingView.setSecondSideDiceBgColor(Color.WHITE); //设置第二面骰子背景颜色
diceLoadingView.setSecondSideDiceBorderColor(Color.BLUE); //设置第二面骰子边界颜色diceLoadingView.setThirdSideDiceNumber(4); //设置第三面骰子点数(1-6)
diceLoadingView.setThirdSidePointColor(Color.GREEN); //设置第三面骰子点的颜色
diceLoadingView.setThirdSideDiceBgColor(Color.WHITE); //设置第三面骰子背景颜色
diceLoadingView.setThirdSideDiceBorderColor(Color.GREEN); //设置第三面骰子边界颜色diceLoadingView.setFourthSideDiceNumber(5); //设置第四面骰子点数(1-6)
diceLoadingView.setFourthSidePointColor(Color.RED); //设置第四面骰子点的颜色
diceLoadingView.setFourthSideDiceBgColor(Color.WHITE); //设置第四面骰子背景颜色
diceLoadingView.setFourthSideDiceBorderColor(Color.RED); //设置第四面骰子边界颜色
复制代码

属性说明:

开始描述效果图之前,先看两张张说明图:

针对立方体而言

针对每一个骰子面而言:

attrdescription
animDuration动画时间
animInterpolator动画加速器
firstSideDiceNumber第一面骰子点数(1-6)
firstSideDicePointColor第一面骰子点的颜色
firstSideDiceBgColor第一面骰子背景颜色
firstSideDiceBorderColor第一面骰子边界颜色
secondSideDiceNumber第二面骰子点数(1-6)
secondSideDicePointColor第二面骰子点的颜色
secondSideDiceBgColor第二面骰子背景颜色
secondSideDiceBorderColor第二面骰子边界颜色
thirdSideDiceNumber第三面骰子点数(1-6)
thirdSideDicePointColor第三面骰子点的颜色
thirdSideDiceBgColor第三面骰子背景颜色
thirdSideDiceBorderColor第三面骰子边界颜色
fourthSideDiceNumber第四面骰子点数(1-6)
fourthSideDicePointColor第四面骰子点的颜色
fourthSideDiceBgColor第四面骰子背景颜色
fourthSideDiceBorderColor第四面骰子边界颜色

[Github](https://github.com/samlss/DiceLoadingView)

相关文章:

职业生涯的考虑

职业核心价值&#xff1a;活的有价值&#xff0c;有意义 第一阶段&#xff1a;技术&#xff08;27:2012&#xff5e;30:2015&#xff09;&#xff1a;移动互联网 第二阶段&#xff1a;销售或者管理&#xff08;30:2015&#xff5e;35:2020&#xff09;&#xff1a;成熟公司 第三…

算法的sound和complete

stackoverflow的答案 Soundness and Completeness of a algorithm stackexchange的答案 What does it mean to say an algorithm is Sound and Complete?

ArcGIS API for Silverlight 入门学习笔记(三):基础地图实例

该实例主要是包含六部分&#xff1a;地图范围、坐标、动画效果、全屏、比例尺、进度条。 前期准备工作 前台代码0 <UserControl x:Class"APIforSilverlightSamp.s2" xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x"ht…

BZOJ 4009 接水果

Description 风见幽香非常喜欢玩一个叫做osu!的游戏&#xff0c;其中她最喜欢玩的模式就是接水果。 由于她已经DT FC了The big black, 她觉得这个游戏太简单了&#xff0c;于是发明了一个更加难的版本。首先有一个地图&#xff0c;是一棵由\(n\)个顶点、\(n-1\)条边组成的树。这…

GitBook本地的安装与查看

1.安装nodejs 2.cnpm install -g gitbook-cli 查看版本&#xff1a;gitbook -V 3.gitbook init 注意npm加了代理&#xff0c;查看npm代理配置&#xff0c;将其注释即可 执行完后&#xff0c;你会看到多了两个文件 —— README.md 和 SUMMARY.md&#xff0c;它们的作用如下&…

用C++的random_shuffle()函数打乱int数组顺序

程序背景&#xff1a; 开组会&#xff0c;汇报人已确定&#xff0c;出一个随机的汇报顺序。 #include<bits/stdc.h> using namespace std;const int NUM 12;//汇报人数 int main() {string names[] {"SpongeBob","Patrick","Squidward"…

ios 绘制不规则 图形

最近才知道有一个软件 paintcode 它可以根据画出的图形自动的生成对应的 OC 代码 不用UI切图 我们也可以用代码实现自己想要的图形效果 使用教程可以百度&#xff1a;paintcode教程 http://blog.csdn.net/lujunelong/article/details/18899925 下载地址&#xff1a;http://www…

[转]Windows与VC命名规则

转自&#xff1a;http://hi.baidu.com/11158512/blog/item/0fbd5535cbfb5d1c91ef3970.html 匈牙利命名法是一种编程时的命名规范。基本原则是&#xff1a;变量名&#xff1d;属性&#xff0b;类型&#xff0b;对象描述。其中每一对象的名称都要求有明确含义&#xff0c;可以取对…

恢复误删的进程在使用的文件【转】

转自&#xff1a;https://www.cnblogs.com/276815076/p/5473185.html 原理&#xff1a;在Linux系统的/proc 分区下保存着进程的目录和名字&#xff0c;包含fd(文件描述符)和其下的子目录&#xff08;进程打开文件的链接&#xff09;&#xff0c;那么如果删除了一个文件&#xf…

编解码器架构中的桥(bridge)指什么

https://opennmt.net/OpenNMT-py/examples/Summarization.html?highlightbridge​​​​​​对于bridge做出如下解释 bridge: This is an additional layer that uses the final hidden state of the encoder as input and computes an initial hidden state for the decoder.…

控件包含代码块,因此无法修改控件集合

文章转载至: http://www.olnote.com/itlife/note/100000003.aspx控件包含代码块(即<% ... %>)&#xff0c;因此无法修改控件集合。 说明: 执行当前 Web 请求期间&#xff0c;出现未处理的异常。请检查堆栈跟踪信息&#xff0c;以了解有关该错误以及代码中导致错误的出处…

驰骋工作流引擎JFlow与activiti的对比之4种包含多实例的模式

为什么80%的码农都做不了架构师&#xff1f;>>> 4种包含多实例的模式 无同步的多实例&#xff08;MIwithout&#xff09;在流程中&#xff0c;一个活动可以激活多个实例&#xff0c;每个实例相互独立&#xff0c;并不需要在后面进行同步。 例子&#xff1a;比如用户…

Embarcadero Dev C++ 中文输出乱码

解决方式&#xff1a;保证编译器和文件的编码方式一样。 1. 编译器的编码方式 Embarcadero Dev C 界面 2. cpp文件编码方式 Notepad界面

关于登录记住密码使用cookie的详解

下面是我看的一篇文章引用过来&#xff0c;很易懂 设置cookie每个cookie都是一个名/值对&#xff0c;可以把下面这样一个字符串赋值给document.cookie&#xff1a;document.cookie"userId828";如果要一次存储多个名/值对&#xff0c;可以使用分号加空格&#xff08;;…

Linux服务器---安装tftp-server

安装tftp-server1、安装tftp-server[rootlocalhost weijie]# yum install -y tftp-serverLoaded plugins: fastestmirror, refresh-packagekit, securityRunning TransactionInstalling : tftp-server-0.49-8.el6.i686 1/1 Verifying : tftp…

linux指令 2>1 到底是个啥

训练好深度学习模型之后对其进行测试&#xff0c;测试的脚本如上图。 我对第11行感到不解&#xff0c;经过检索Linux重定向和文件描述符相关知识后&#xff0c;明白了 2代表着标准错误 1代表者标准输出(默认是屏幕) >代表流向 那么第11行代码的含义也就是&#xff0c;将…

新生 语不惊人死不休 —— 《无限恐怖》读后有感

开篇声明&#xff0c;我博客中“小心情”这一系列&#xff0c;全都是日记啊随笔啊什么乱七八糟的。如果一不小心点进来了&#xff0c;不妨直接关掉。我自己曾经写过一段时间的日记&#xff0c;常常翻看&#xff0c;毫无疑问我的文笔是很差的&#xff0c;而且心情也是瞬息万变的…

中国大学MOOC-C程序设计(浙大翁恺)—— 时间换算

时间换算&#xff08;10分&#xff09;题目内容&#xff1a;UTC是世界协调时&#xff0c;BJT是北京时间&#xff0c;UTC时间相当于BJT减去8。现在&#xff0c;你的程序要读入一个整数&#xff0c;表示BJT的时和分。整数的个位和十位表示分&#xff0c;百位和千位表示小时。如果…

作为一个程序员,数学对你到底有多重要(转)

每个计算机系毕业的人&#xff0c;大都学过不少数学课&#xff0c;而且不少学校的计算机系的数学课&#xff0c;通常比一般的其他工科专业的数学要难一些&#xff0c;比如不上高等数学&#xff0c;而是学数学分析&#xff0c;不上线性代数而去上高等代数。但是&#xff0c;大部…

如何在vsc上选择远程miniconda特定的虚拟环境中的Python解释器(4步)

前提&#xff1a; 已经通过remote development插件连上了远程服务器 远程服务器上已经创建了安装了python的虚拟环境 步骤&#xff1a; 点击“查看” 点击“命令面板” 输入/选择 Python:Select Interpreter 然后就能选择远程miniconda中已经创建的虚拟环境了 我的minico…

Java数据类型简单认识

Java是一种强类型编程语言&#xff0c;因而在声明变量的时候必须声明数据类型&#xff0c;java语言有基本数据类型和引用数据类型这两大数据类型&#xff0c;基本数据类型有8种分别是4种整型、2种浮点类型、1种用于Unicode表示字符单元的字符类型和1种表示真值的布尔类型;引用数…

Intel 6系列芯片组设计缺陷 全球出货暂停

美国当地时间周一&#xff0c;Intel公司官方宣布&#xff0c;今年1月初刚刚伴随Sandy Bridge系列“第二代Core架构处理器”推出的6系列芯片组&#xff08;代号Cougar Point&#xff09;发现了设计方面的问题。虽然目前Intel已经对该设计在芯片级别进行了修正&#xff0c;但在新…

PrestaShop 网站漏洞修复如何修复

2019独角兽企业重金招聘Python工程师标准>>> PrestaShop网站的漏洞越来越多&#xff0c;该网站系统是很多外贸网站在使用的一个开源系统&#xff0c;从之前的1.0初始版本到现在的1.7版本&#xff0c;经历了多次的升级&#xff0c;系统使用的人也越来越多&#xff0c…

shell脚本中的case语句使用要点

1.双分号(;;) 用于case语句中一个分支的结束。 可类比C里面switch...case语句&#xff0c;在case语句之后&#xff0c;若所有语句都输完&#xff0c;后面跟着的"break;"。 2.星号加右小括号*) 可类比C里面switch...case语句中的"default:"。 3.结束符…

Netty - ByteBuf

2019独角兽企业重金招聘Python工程师标准>>> 1.ByteBuf类 - Netty的数据容器 ByteBuf维护了两个不同的索引&#xff1a; readerIndex&#xff1a;用于读取writerIndex&#xff1a;用于写入起始位置都从0开始&#xff1a; 名称以read或者write开头的方法会更新ByteBu…

不要做浮躁的嵌入式系统工程师

每天读一遍&#xff0c;思考一下&#xff1a;我是否浮躁&#xff1f; 1、不要看到别人的回复&#xff0c;第一句话就说&#xff1a;给个代码吧&#xff01;你应该想想为什么。当你自己想出来再参考别人的提示&#xff0c;就会知道自己和别人思路的差异。 2、初学者请不要看…

Codeforces Round #300 A. Cutting Banner 水题

A. Cutting Banner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/problem/ADescription A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfo…

ImportError:cannot import name ‘display‘ File “XX“, line 5, in <module> from IPython import display

导入错误问题的一个解决思路是&#xff0c;推断这是模块间版本不兼容带来的问题&#xff0c;先把模块卸载掉&#xff0c;再用conda install安装上。也就是让conda去协调模块间兼容性。

[高级]android应用开发之intent的妙用二

相信做android应用开发的朋友对intent组件都已经是相当熟悉了&#xff0c;这里鄙人总结一下intent的妙用&#xff0c;希望对大家有帮助。 intent妙用之列出所有已安装的应用程序列表 装载&#xff1a;http://blog.csdn.net/android_tutor/article/details/5724634 这篇文章写的…

windows 自动化目录大纲(各企业架构不一样,按需选择)

有需要做自动化的联系979122932,一起交流学习转载于:https://blog.51cto.com/7763608/2338668