项目作者: hspbc666

项目描述 :
An android custom view of circle progress.
高级语言: Kotlin
项目地址: git://github.com/hspbc666/circleProgress.git
创建时间: 2019-09-04T01:05:54Z
项目社区:https://github.com/hspbc666/circleProgress

开源协议:

下载


windmill 旋转风车

博客:https://blog.csdn.net/yinxing2008/article/details/100260191

旋转风车实现效果

实现方案

对于风车的立柱部分,采用一张固定背景图;
对于风车上面旋转部分,采用一张图,通过安卓属性动画进行旋转。
注意点: 因为是采用两张图叠加而形成的效果,所以需要注意调整两张图的相对位置,使之刚好形成风车旋转效果。

主要代码

  1. BaseWindmillView.kt

    1. abstract class BaseWindmillView constructor(context: Context, attrs: AttributeSet? = null) :
    2. LinearLayout(context, attrs) {
    3. private fun getRotateAnimation(@IntRange(from = 1, to = 10) speed: Int): RotateAnimation {
    4. val animateTime = getAnimateTimeFromSpeed(speed)
    5. val animation = RotateAnimation(
    6. 0f, 360f,
    7. Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f
    8. )
    9. animation.fillAfter = true
    10. animation.repeatCount = Animation.INFINITE
    11. animation.duration = animateTime
    12. animation.interpolator = LinearInterpolator()
    13. return animation
    14. }
    15. private fun getAnimateTimeFromSpeed(speed: Int): Long {
    16. return (10 * 1000 / speed).toLong()
    17. }
    18. fun startRotate(@IntRange(from = 1, to = 10) speed: Int) {
    19. getToRotateViews().forEach {
    20. it.clearAnimation()
    21. it.startAnimation(getRotateAnimation(speed)) }
    22. }
    23. abstract fun getToRotateViews(): List<View>
    24. }
  2. DoubleWindmillView.kt
    ```
    class DoubleWindmillView constructor(context: Context, attrs: AttributeSet? = null) :
    BaseWindmillView(context, attrs) {
    init {

    1. LayoutInflater.from(context).inflate(R.layout.view_double_windmill, this, true)

    }

    override fun getToRotateViews()= listOf(windmillBladeIv,smallWindmillBladeIv)

}

  1. 3. view_double_windmill.xml

<?xml version=”1.0” encoding=”utf-8”?>

  1. <ImageView
  2. android:id="@+id/windmillBladeIv"
  3. android:layout_width="80dp"
  4. android:layout_height="80dp"
  5. android:src="@mipmap/windmill_blade" ></ImageView>
  6. <ImageView
  7. android:layout_width="24dp"
  8. android:layout_height="80dp"
  9. android:layout_marginStart="29dp"
  10. android:layout_marginTop="32dp"
  11. android:src="@mipmap/windmill" ></ImageView>
  12. <ImageView
  13. android:id="@+id/smallWindmillBladeIv"
  14. android:layout_width="48dp"
  15. android:layout_height="48dp"
  16. android:layout_marginStart="50dp"
  17. android:layout_marginTop="30dp"
  18. android:src="@mipmap/windmill_blade" ></ImageView>
  19. <ImageView
  20. android:layout_width="14dp"
  21. android:layout_height="48dp"
  22. android:layout_marginStart="67dp"
  23. android:layout_marginTop="50dp"
  24. android:src="@mipmap/windmill" ></ImageView>

  1. # lib库集成方法
  2. 1. 在工程根目录下build.gradle文件中增加jitpack仓库地址:

allprojects {
repositories {

maven { url ‘https://jitpack.io‘ }
}
}

  1. 2. app工程下build.gradle文件中增加依赖:

dependencies {
implementation ‘com.github.cxyzy1:windmill:1.0.0’
}
```