<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          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)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  丁香操逼| 亚洲天堂在线观看网站 | 波多野结衣在线不卡 | 壁特壁最新视频 | 韩国三级在线视频观看 |