旋转风车实现效果

实现方案

对于风车的立柱部分,采用一张固定背景图;

对于风车上面旋转部分,采用一张图,通过安卓属性动画进行旋转。

注意点: 因为是采用两张图叠加而形成的效果,所以需要注意调整两张图的相对位置,使之刚好形成风车旋转效果。

主要代码

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 天气动画,安卓实现旋转风车动画(仿华为天气预报)相关推荐

  1. CSS3动画制作的旋转风车,大家五一节日快乐

    ✅作者简介: 大家好五一快乐,我是痴心阿文,你们的学友哥,今天给大家分享一个CSS3动画制作的旋转风车!

  2. 纯CSS制作3D旋转风车动画效果

    效果图展示        HTML源码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"&g ...

  3. Android中实现ProgressBar菊花旋转的动画效果

    在一些常见到的加载中需要显示一个加载动画,如旋转的菊花,旋转的圈圈等等动画-,然后我们现在就来说下怎么去试下它吧 一.菊花的旋转动画 1.新建一个drawable文件 在res/drawable下新建 ...

  4. Android 天气APP(十一)未来七天的天气预报、逐小时预报、UI优化

    上一篇:Android 天气APP(十)下拉刷新页面天气数据 逐小时天气预报.UI优化 新版------------------- 一.UI优化 二.逐小时天气预报 ① 添加逐小时天气API ② 使用 ...

  5. android平板交互,安卓平板就应该如此,华为MatePad Pro 交互体验

    原标题:安卓平板就应该如此,华为MatePad Pro 交互体验 在华为正式发布华为MatePad Pro后,IT之家小编正正发现大家把讨论的焦点都集中在了屏幕打孔上.对此,已经使用华为MatePad ...

  6. android 动画x轴旋转,属性动画Rotation如何以中心轴旋转

    //这个是按照某一点进行旋转,默认是view的 ObjectAnimator oaAnimator=ObjectAnimator.ofFloat(imageView1, "rotation& ...

  7. 定格动画android,定格动画安卓版下载-定格动画最新版下载v2.2.2-一听下载站

    定格动画是一个针对喜欢剪辑的用户们创作的软件,各种的是一个制作定格动画,这个软件让喜欢制作定格动画的用户们在手机上也能够进行使用,是所有需要制作定格动画那一个必备助手,整个的操作也是非常的简单,只需要 ...

  8. android6.0关机动画,安卓系统修改开机动画,关机动画

    开机动画 两种开机动画 关于安卓动画的研究主要在frameworks/base/cmds/bootanimation/BootAnimation.cpp中. 安卓系统默认的开机动画(谷歌)的动画是显示 ...

  9. 《Android自定义控件》时钟、钟表AlarmClockView,仿华为手机世界时钟控件效果

    转载请标明出处:https://blog.csdn.net/m0_38074457/article/details/85790550,本文出自[陈少华的博客] 一.效果图 二.控件结构 三.代码实现 ...

最新文章

  1. 中国互联网+户外广告行业商业模式创新与投资机会深度研究报告
  2. SAP HUM 如何将HU里的物料号换成另外一个物料号?
  3. JavaScript--关于实例对象带不带参数和构造函数带不带参数的关系
  4. 百度开源分布式id生成器uid-generator源码剖析
  5. JVM统介——Java虚拟机架构
  6. 学习string,stringBuffer时遇到的问题
  7. 特征提取(Feature Detection)之——HOG (Histogram of Oriented Gradient)特征
  8. 敏捷估算:故事点与直接估算天数的差异
  9. JWT实现加密用户信息及信息验证
  10. 三种短链接生成源码-iApp源码
  11. 百度地图离线调用(详细教程)
  12. python3写360图库爬虫
  13. echarts设置主标题和副标题样式
  14. 微信小程序协同工作和发布
  15. echo和narcissus寓意_希腊神话故事(一)Echo 和 Narcissus
  16. annotate 函数的用法
  17. NLP task2 N-Gram
  18. 2020届部分校招IC笔试题
  19. vnc支持用计算机民远程吗,使用vnc连接远程计算机
  20. win10环境下Android SDK下载安装及配置教程

热门文章

  1. 用Rayleigh-Ritz法求解梁的固有频率并用有限元校核
  2. html符号转义字符,HTML转义符号
  3. 赏析角度有哪些_在古诗词鉴赏中可以从哪些角度赏析句子的表达效果
  4. 基于stm32单片机的Grayhill编码器/开关软件设计
  5. query和params传参区别
  6. 今日词话:点绛唇·感兴
  7. linux禁用光驱自动播放,电脑光驱怎么设置禁止自动播放?
  8. 使用 Single-SPA 从零开始搭建 React 微前端项目
  9. 卷烟流水线工人超30%是研究生
  10. 【日志框架-笔记】JUL日志框架的介绍及其使用