1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Android仿華為天氣實(shí)現(xiàn)旋轉(zhuǎn)風(fēng)車(chē)動(dòng)畫(huà)效果

        共 1886字,需瀏覽 4分鐘

         ·

        2021-11-18 02:23

        旋轉(zhuǎn)風(fēng)車(chē)實(shí)現(xiàn)效果:



        實(shí)現(xiàn)方案

        ?

        對(duì)于風(fēng)車(chē)的立柱部分,采用一張固定背景圖;

        對(duì)于風(fēng)車(chē)上面旋轉(zhuǎn)部分,采用一張圖,通過(guò)安卓屬性動(dòng)畫(huà)進(jìn)行旋轉(zhuǎn)。

        注意點(diǎn):因?yàn)槭遣捎脙蓮垐D疊加而形成的效果,所以需要注意調(diào)整兩張圖的相對(duì)位置,使之剛好形成風(fēng)車(chē)旋轉(zhuǎn)效果。


        主要代碼


        1、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}


        2、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)
        }


        3、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庫(kù)集成方法


        1、在工程根目錄下build.gradle文件中增加jitpack倉(cāng)庫(kù)地址:

        allprojects {    repositories {        ...        maven { url 'https://jitpack.io' }    }}


        2、在app工程下build.gradle文件中增加依賴:

        dependencies {    implementation 'com.github.cxyzy1:windmill:1.0.0'}


        源碼地址:
        https://github.com/cxyzy1/windmill

        到這里就結(jié)束啦。
        瀏覽 43
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            放荡勾人引诱h | 久久精品人人做人人爽电影蜜月 | 美女图片一区二区 | 男女拍拍视频免费看 | 青娱乐亚洲成人在线视频观看 | 亚洲最大视频 | 草久久久久久久久久久久 | 午夜视频h | 大香蕉国产在线看 | 夜夜嗨av一区二区三区四区 |