<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 1. View動畫 針對對象是`View`,支持四種動畫:平移、縮放、旋轉、透明度。這四種動畫對應著`Animation`的四個子類:`TranslateAnimation`、`ScaleAnimation`、`RotateAnimation`和`AlphaAnimation`。均支持使用`xml`和動態代碼創建。當然,對于`View`動畫來說建議使用`xml`方式,因為可讀性更好。 上述四種動畫對應的`xml`標簽:`translate`、`scale`、`rotate`、`alpha`。也就是對應的開頭的單詞小寫。 # 2. 平移動畫 ## 2.1 xml方式 在`res/anim`目錄下創建`translate01.xml`文件: ~~~ <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="200" android:toYDelta="500" android:interpolator="@android:anim/linear_interpolator" android:duration="2000" > </translate> </set> ~~~ 這里對上述屬性做一個簡單的介紹: * `android:interpolator`,用來指定一個插值器,會影響動畫的播放速度。比如默認為`@android:anim/accelerate_decelerate_interpolator`,也就是加速減速插值器。 * `android:fillAfter`,用來指定`View`動畫結束后,是否停留在結束為止; * `android:duration`,用來指定`View`動畫持續時間; 然后我們將上述動畫,通過`View`對象的`startAnimation(animation)`來進行關聯: ~~~ val btn by lazy { findViewById<Button>(R.id.btn) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btn.setOnClickListener { val animation = AnimationUtils.loadAnimation(this, R.anim.translate01) btn.startAnimation(animation) } } ~~~ 結果: ![](https://img.kancloud.cn/e0/fe/e0fe97107e33381c091bd1c44335d1c4_376x396.png) ## 2.2 kotlin代碼方式 除了使用`xml`方式配置,也可以直接創建一個`animation`對象,然后配置動畫效果,即: ~~~ val btn by lazy { findViewById<Button>(R.id.btn) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btn.setOnClickListener { val animation = TranslateAnimation(0f, 200f, 0f, 300f) animation.interpolator = AccelerateDecelerateInterpolator(); animation.fillAfter = true animation.duration = 2000 btn.startAnimation(animation) } } ~~~ 效果同上,這里就不再截圖。 # 3. 縮放動畫 ## 3.1 xml方式 ~~~ <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <scale android:fromXScale="0.5" android:toXScale="2" android:fromYScale="1" android:toYScale="2" android:duration="2000" > </scale> </set> ~~~ 然后,這里還是應用在`Button`上: ~~~ btn.setOnClickListener { val animation = AnimationUtils.loadAnimation(this, R.anim.scale01) btn.startAnimation(animation) } ~~~ 效果: ![](https://img.kancloud.cn/47/95/4795b0a4b574440120adc3dc80cd2a65_372x192.png) # 4. 旋轉動畫 ~~~ <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true"> <rotate android:fromDegrees="0" android:toDegrees="180" android:duration="2000" android:pivotX="200" android:pivotY="200" > </rotate> </set> ~~~ ![](https://img.kancloud.cn/0b/c7/0bc74ca247adb1f856344c654a193820_368x252.png) # 5. 透明動畫 `kotlin`代碼方式: ~~~ btn.setOnClickListener { val animation = AlphaAnimation(1f, 0f) animation.duration = 2000 animation.fillAfter = true // 保持最后狀態 btn.startAnimation(animation) } ~~~ `xml`布局方式: ~~~ <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="2000" > </alpha> </set> ~~~ 效果就不再截圖。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看