Android Tween Animation,androidtween

來源:互聯網
上載者:User

Android Tween Animation,androidtween

View Animation, 即顯示在view上的Tween Animation

Tween動畫,本質上不改變View對象本身,只改變它的繪製方式

兩種實現方式,一種在xml中定義,一種直接在代碼裡定義

xml定義方式:位移動畫translate

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromXDelta="10"    android:fromYDelta="0"    android:toXDelta="50%"     android:toYDelta="50%p"    android:repeatCount="50"    android:repeatMode="reverse"    android:fillAfter="true"><!-- repeatCount動畫再次重複的次數repeatMode   這一次反轉上一次的效果 fillAfter動畫結束後,view停留在動畫結束時的位置  view的實際位置並沒有改變50%p 相對於父布局50%  相對於自身 --></translate>
旋轉動畫rotate
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromDegrees="0"     android:toDegrees="-90"    android:pivotX="50%"    android:pivotY="50%"    android:repeatCount="50"    android:repeatMode="reverse"    android:fillAfter="true"><!-- fromDegrees="0" 開始角度toDegrees="-90"結束角度pivotX="50%"中心點xpivotY="50%"中心點y --></rotate>
透明度漸層動畫alpha
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromAlpha="0"    android:toAlpha="1"    android:fillAfter="true"    android:repeatCount="50"    android:repeatMode="reverse" ><!-- fromAlpha開始的透明度  0完全透明toAlpha結束的透明度  1完全不透明 --></alpha>
縮放動畫scale
<?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fromXScale="0.5"    android:fromYScale="1"    android:toXScale="3"    android:toYScale="2"    android:pivotX="50%"    android:pivotY="50%"    android:fillAfter="true"    android:repeatCount="50"    android:repeatMode="reverse"  ><!-- scale 縮放比率 --></scale>

動畫集

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="2000"    android:fillAfter="true"    android:repeatCount="50"    android:repeatMode="reverse" >    <scale        android:fromXScale="0.5"        android:fromYScale="1"        android:pivotX="50%"        android:pivotY="50%"        android:repeatCount="50"        android:repeatMode="reverse"        android:toXScale="3"        android:toYScale="2" />    <alpha        android:fromAlpha="0"        android:repeatCount="50"        android:repeatMode="reverse"        android:toAlpha="1" />    <translate        android:fromXDelta="10"        android:fromYDelta="0"        android:repeatCount="50"        android:repeatMode="reverse"        android:toXDelta="50%"        android:toYDelta="50%p" />    <rotate        android:fromDegrees="0"        android:pivotX="50%"        android:pivotY="50%"        android:repeatCount="50"        android:repeatMode="reverse"        android:toDegrees="-100" /></set>

代碼載入這些xml定義的動畫

Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);imageview_translate.setBackground(getResources().getDrawable(R.drawable.a11));imageview_translate.startAnimation(translate);Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);imageview_rotate.setBackground(getResources().getDrawable(R.drawable.a11));imageview_rotate.startAnimation(rotate);Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);imageview_alpha.setBackground(getResources().getDrawable(R.drawable.a11));imageview_alpha.startAnimation(alpha);Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);imageview_scale.setBackground(getResources().getDrawable(R.drawable.a11));imageview_scale.startAnimation(scale);Animation set = AnimationUtils.loadAnimation(this, R.anim.set);imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));imageview_set.startAnimation(set);

純程式碼建立Tween Animation

AnimationSet animationSet = new AnimationSet(true);animationSet.addAnimation(scale);animationSet.addAnimation(translate);animationSet.addAnimation(alpha);animationSet.addAnimation(rotate);animationSet.setDuration(2000);animationSet.setRepeatCount(50);animationSet.setRepeatMode(Animation.RESTART);//animationSet.setRepeatMode(Animation.REVERSE);imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));imageview_set.startAnimation(animationSet);TranslateAnimation translateAnimation;RotateAnimation rotateAnimation;AlphaAnimation alphaAnimation;ScaleAnimation scaleAnimation;//Animation.RELATIVE_TO_SELF相對於自身//Animation.RELATIVE_TO_PARENT 相對於父View

設定動畫監聽器

scale.setAnimationListener(new AnimationListener() {@Override //動畫開始public void onAnimationStart(Animation animation) {}@Override //動畫重複public void onAnimationRepeat(Animation animation) {}@Override //動畫結束public void onAnimationEnd(Animation animation) {}});
動畫插入器Interpolator

在animation的xml和代碼中 可以設定動畫的插入器,它用來指示動畫在期間內的動作的速率變化

android:interpolator="@android:anim/overshoot_interpolator"OvershootInterpolator

 <!--  預設情況下:動畫隨著時間的推移 均勻的被應用,要改變這種效果可以使用插入器 interpolator 設定插入器 accelerate_interpolator  類似加速度先小後大, 開始慢 後漸快  變速運動  accelerate_decelerate_interpolator類似加速度先大後小, 先加速 後減速 變速運動  anticipate_interpolatorthe change starts backward then flings forward 先減(減到比開始值還小一點),後加(加到結束值) anticipate_overshoot_interpolator先減(減到比開始值還小一點),後加(加到比結束值還大一點,再回退到結束值) overshoot_interpolator直接加速到結束值,並比結束值還大一點,再回退到結束值  bounce_interpolator反彈結束時的變化 到達結束值時一會小一會大 來回兩次 cycle_interpolator先快速從開始到結束值,再遵循正弦模式繼續運動 (左右對切,上下對切) linear_interpolator類似加速度為0,速率不變, 勻速運動 不定義插入器時使用的預設值   -->




在android中Tween動畫各位看看為何效果出不來

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView = (ImageView) findViewById(R.id.imageView1);
dtv = (DTextView) findViewById(R.id.textView111);
findViewById(R.id.textView111).setVisibility(
View.VISIBLE);
dtv.setText("1231231321");
button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

// TODO Auto-generated method stub
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation alphaAnimation = new AlphaAnimation(100, 0);
alphaAnimation.setDuration(5000);
alphaAnimation.setFillAfter(true);

RotateAnimation rotateAnimation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(5000);
rotateAnimation.setFillAfter(true);

ScaleAnimation scaleAnimation = new ScaleAnimation(0, 0.1f, 0, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(3000);

TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0.5f);
translateAnimation.setDuration(3000);
translateAnimation.setFillAfter(true);

animationSet.addAnimation(rotateAni......餘下全文>>
 
什是Tween Animation?什是Frame Animation?它們的不同是什?菜助

frame animation 是逐幀動畫這個在動畫當中還是比較普遍的,大多二維動畫都是逐幀的.tween animation可能是漸層動畫,剛才在網上查了下,好像遊戲,或者屏保那些漸層動畫(靠一些編程代碼實現的動畫叫 tween animation.這些是基於網上的資料的猜測.
個人認為還有一種可能,從字面上理解可能是 frame animation = key-frame animation(主要畫面格動畫,原畫); tween animation =inbetween animation(中間幀動畫,動畫). 如果是意思是後者的話我只能說不同地方翻譯方法不同,或者是某個人用中式英文把這些詞語翻譯成這樣的.
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.