android 天气动画,安卓实现旋转风车动画(仿华为天气预报)
旋转风车实现效果
实现方案
对于风车的立柱部分,采用一张固定背景图;
对于风车上面旋转部分,采用一张图,通过安卓属性动画进行旋转。
注意点: 因为是采用两张图叠加而形成的效果,所以需要注意调整两张图的相对位置,使之刚好形成风车旋转效果。
主要代码
BaseWindmillView.kt
abstract class BaseWindmillView constructor(context: Context, attrs: AttributeSet? = null) :
LinearLayout(context, attrs) {
private fun getRotateAnimation(@IntRange(from = 1, to = 10) speed: Int): RotateAnimation {
val animateTime = getAnimateTimeFromSpeed(speed)
val animation = RotateAnimation(
0f, 360f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f
)
animation.fillAfter = true
animation.repeatCount = Animation.INFINITE
animation.duration = animateTime
animation.interpolator = LinearInterpolator()
return animation
}
private fun getAnimateTimeFromSpeed(speed: Int): Long {
return (10 * 1000 / speed).toLong()
}
fun startRotate(@IntRange(from = 1, to = 10) speed: Int) {
getToRotateViews().forEach {
it.clearAnimation()
it.startAnimation(getRotateAnimation(speed)) }
}
abstract fun getToRotateViews(): List
}
DoubleWindmillView.kt
class DoubleWindmillView constructor(context: Context, attrs: AttributeSet? = null) :
BaseWindmillView(context, attrs) {
init {
LayoutInflater.from(context).inflate(R.layout.view_double_windmill, this, true)
}
override fun getToRotateViews()= listOf(windmillBladeIv,smallWindmillBladeIv)
}
view_double_windmill.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:background="#1E90FF">
android:id="@+id/windmillBladeIv"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@mipmap/windmill_blade" />
android:layout_width="24dp"
android:layout_height="80dp"
android:layout_marginStart="29dp"
android:layout_marginTop="32dp"
android:src="@mipmap/windmill" />
android:id="@+id/smallWindmillBladeIv"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="50dp"
android:layout_marginTop="30dp"
android:src="@mipmap/windmill_blade" />
android:layout_width="14dp"
android:layout_height="48dp"
android:layout_marginStart="67dp"
android:layout_marginTop="50dp"
android:src="@mipmap/windmill" />
lib库集成方法
在工程根目录下build.gradle文件中增加jitpack仓库地址:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在app工程下build.gradle文件中增加依赖:
dependencies {
implementation 'com.github.cxyzy1:windmill:1.0.0'
}
完整源代码
android 天气动画,安卓实现旋转风车动画(仿华为天气预报)相关推荐
- CSS3动画制作的旋转风车,大家五一节日快乐
✅作者简介: 大家好五一快乐,我是痴心阿文,你们的学友哥,今天给大家分享一个CSS3动画制作的旋转风车!
- 纯CSS制作3D旋转风车动画效果
效果图展示 HTML源码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"&g ...
- Android中实现ProgressBar菊花旋转的动画效果
在一些常见到的加载中需要显示一个加载动画,如旋转的菊花,旋转的圈圈等等动画-,然后我们现在就来说下怎么去试下它吧 一.菊花的旋转动画 1.新建一个drawable文件 在res/drawable下新建 ...
- Android 天气APP(十一)未来七天的天气预报、逐小时预报、UI优化
上一篇:Android 天气APP(十)下拉刷新页面天气数据 逐小时天气预报.UI优化 新版------------------- 一.UI优化 二.逐小时天气预报 ① 添加逐小时天气API ② 使用 ...
- android平板交互,安卓平板就应该如此,华为MatePad Pro 交互体验
原标题:安卓平板就应该如此,华为MatePad Pro 交互体验 在华为正式发布华为MatePad Pro后,IT之家小编正正发现大家把讨论的焦点都集中在了屏幕打孔上.对此,已经使用华为MatePad ...
- android 动画x轴旋转,属性动画Rotation如何以中心轴旋转
//这个是按照某一点进行旋转,默认是view的 ObjectAnimator oaAnimator=ObjectAnimator.ofFloat(imageView1, "rotation& ...
- 定格动画android,定格动画安卓版下载-定格动画最新版下载v2.2.2-一听下载站
定格动画是一个针对喜欢剪辑的用户们创作的软件,各种的是一个制作定格动画,这个软件让喜欢制作定格动画的用户们在手机上也能够进行使用,是所有需要制作定格动画那一个必备助手,整个的操作也是非常的简单,只需要 ...
- android6.0关机动画,安卓系统修改开机动画,关机动画
开机动画 两种开机动画 关于安卓动画的研究主要在frameworks/base/cmds/bootanimation/BootAnimation.cpp中. 安卓系统默认的开机动画(谷歌)的动画是显示 ...
- 《Android自定义控件》时钟、钟表AlarmClockView,仿华为手机世界时钟控件效果
转载请标明出处:https://blog.csdn.net/m0_38074457/article/details/85790550,本文出自[陈少华的博客] 一.效果图 二.控件结构 三.代码实现 ...
最新文章
- 中国互联网+户外广告行业商业模式创新与投资机会深度研究报告
- SAP HUM 如何将HU里的物料号换成另外一个物料号?
- JavaScript--关于实例对象带不带参数和构造函数带不带参数的关系
- 百度开源分布式id生成器uid-generator源码剖析
- JVM统介——Java虚拟机架构
- 学习string,stringBuffer时遇到的问题
- 特征提取(Feature Detection)之——HOG (Histogram of Oriented Gradient)特征
- 敏捷估算:故事点与直接估算天数的差异
- JWT实现加密用户信息及信息验证
- 三种短链接生成源码-iApp源码
- 百度地图离线调用(详细教程)
- python3写360图库爬虫
- echarts设置主标题和副标题样式
- 微信小程序协同工作和发布
- echo和narcissus寓意_希腊神话故事(一)Echo 和 Narcissus
- annotate 函数的用法
- NLP task2 N-Gram
- 2020届部分校招IC笔试题
- vnc支持用计算机民远程吗,使用vnc连接远程计算机
- win10环境下Android SDK下载安装及配置教程