Android 中 Tweened animation的實(shí)例詳解
Android 中 Tweened animation的實(shí)例詳解
Tweened animation有四種類型,下面主要介紹Scale類型。
運(yùn)行效果如下:

Android SDK提供了2種方法:直接從XML資源中讀取Animation,使用Animation子類的構(gòu)造函數(shù)來(lái)初始化Animation對(duì)象,第二種方法在看了Android SDK中各個(gè)類的說(shuō)明就知道如何使用了,下面簡(jiǎn)要說(shuō)明從XML資源中讀取Animation。XML資源中的動(dòng)畫文件animation.xml內(nèi)容為:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset="3000"
android:duration="3000"
android:repeatCount="4"/>
</set>
主文件ScaleAnimation.java內(nèi)容為:
package com.android.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class TestAnimation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView) findViewById(R.id.imageview);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation);
imageView.startAnimation(animation);
}
}
程序很容易看懂,主要為了說(shuō)明伸縮動(dòng)畫效果而沒(méi)有增加復(fù)雜性。值得說(shuō)明的是,本人在測(cè)試階段,錯(cuò)誤的認(rèn)為不需要布局文件,把行setContentView(R.layout.main);去掉,導(dǎo)致程序運(yùn)行一直出錯(cuò)。其實(shí)動(dòng)畫也需要首先把布局文件加載到Activity里面,然后對(duì)布局里面的控件增加動(dòng)畫。
如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android SpringAnimation彈性動(dòng)畫解析
- Android自定義Animation實(shí)現(xiàn)View搖擺效果
- Android xml實(shí)現(xiàn)animation的4種動(dòng)畫效果實(shí)例代碼
- Android Animation實(shí)戰(zhàn)之一個(gè)APP的ListView的動(dòng)畫效果
- Android Animation實(shí)戰(zhàn)之屏幕底部彈出PopupWindow
- Android動(dòng)畫之漸變動(dòng)畫(Tween Animation)詳解 (漸變、縮放、位移、旋轉(zhuǎn))
- Android動(dòng)畫之逐幀動(dòng)畫(Frame Animation)實(shí)例詳解
相關(guān)文章
android實(shí)現(xiàn)簡(jiǎn)單左滑刪除控件
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)一個(gè)簡(jiǎn)單左滑刪除控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08
AndroidStudio 配置 AspectJ 環(huán)境實(shí)現(xiàn)AOP的方法
本篇文章主要介紹了AndroidStudio 配置 AspectJ 環(huán)境實(shí)現(xiàn)AOP的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
Android實(shí)現(xiàn)一個(gè)簡(jiǎn)易的帶邊輸入框
如今市面上APP的輸入框可以說(shuō)是千奇百怪,不搞點(diǎn)花樣出來(lái)貌似代表格局沒(méi)打開,還在使用系統(tǒng)自帶的輸入框的兄弟可以停下腳步,哥帶你實(shí)現(xiàn)一個(gè)簡(jiǎn)易的帶邊框輸入框,感興趣的同學(xué)可以自己動(dòng)手試一下2023-08-08
Android開發(fā)中amera2 Preview使用詳解
這篇文章主要介紹了Android開發(fā)中amera2 Preview使用詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
Android實(shí)現(xiàn)仿慕課網(wǎng)下拉加載動(dòng)畫
這篇文章是我在做動(dòng)畫的項(xiàng)目中整理出來(lái)的,在eoe看了篇帖子,然后仿慕課網(wǎng)做了一個(gè)下拉加載動(dòng)畫。此功能實(shí)現(xiàn)方法是AnimationDrawable類進(jìn)行 Animation-list中item的循環(huán)遍歷圖片,類似于flash里的幀幀動(dòng)畫,需要的朋友可以參考下2015-07-07

