欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android動(dòng)畫(huà)之補(bǔ)間動(dòng)畫(huà)(Tween Animation)基礎(chǔ)學(xué)習(xí)

 更新時(shí)間:2016年09月27日 10:04:29   作者:思格斯  
補(bǔ)間動(dòng)畫(huà)是指定開(kāi)始和結(jié)束的圖像狀態(tài),自動(dòng)生成需要顯示的過(guò)度圖像的動(dòng)畫(huà)。補(bǔ)間動(dòng)畫(huà)又分為四種:移動(dòng),縮放,旋轉(zhuǎn),通明度等。下面就來(lái)給大家一篇關(guān)于Android中補(bǔ)間動(dòng)畫(huà)的基礎(chǔ)知識(shí),有需要的可以參考學(xué)習(xí)。

前言

之前說(shuō)過(guò)了在Android中,動(dòng)畫(huà)Animation的實(shí)現(xiàn)有兩種方式:Tween Animation(漸變動(dòng)畫(huà))和Frame Animation(幀動(dòng)畫(huà))。漸變動(dòng)畫(huà)是通過(guò)對(duì)場(chǎng)景里的對(duì)象不斷做圖像變換(平移、縮放、旋轉(zhuǎn)等)產(chǎn)生動(dòng)畫(huà)效果。幀動(dòng)畫(huà)則是通過(guò)順序播放事先準(zhǔn)備好的圖像來(lái)產(chǎn)生動(dòng)畫(huà)效果,和電影類(lèi)似。

小編也和大家分享了逐幀動(dòng)畫(huà)的基礎(chǔ)知識(shí),下面我們就來(lái)學(xué)習(xí)下Android中逐幀動(dòng)畫(huà)的基礎(chǔ)知識(shí)。

原理 : 給出開(kāi)始和結(jié)束兩個(gè)關(guān)鍵幀,兩個(gè)關(guān)鍵幀之間的插補(bǔ)幀是由計(jì)算機(jī)自動(dòng)運(yùn)算而得到的。

分類(lèi) : AlphaAnimation(透明度) ScaleAnimation(縮放) TranslateAnimation(位移) RotateAnimation (旋轉(zhuǎn)) AnimationSet(組合)

方式 :

1.在代碼中new

2.在anim文件夾下定義動(dòng)畫(huà)xml資源

效果

代碼

第一步 :準(zhǔn)備動(dòng)畫(huà)資源

目錄

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="2000"
 android:fromAlpha="1.0"
 android:interpolator="@android:anim/linear_interpolator"
 android:toAlpha="0.3">

</alpha>
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:interpolator/linear"
 android:repeatCount="infinite"
 android:repeatMode="reverse"
 android:duration="2000"
 android:fromDegrees="0"
 android:toDegrees="1080">
 android:pivotX="50%"
 android:pivotY="50%"
</rotate>
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator"
 android:duration="2000"
 android:fillAfter="true"
 android:fromXScale="1.0"
 android:fromYScale="1.0"
 android:pivotX="50%"
 android:pivotY="50%"
 android:toXScale="0.3"
 android:toYScale="0.3">

</scale>
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
  android:interpolator="@android:anim/linear_interpolator"
  android:duration="2000"
  android:fromXDelta="10"
  android:fromYDelta="10"
  android:toXDelta="300"
  android:toYDelta="300">

</translate>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator"
 android:duration="2000">

 <alpha android:fromAlpha="0.3"
  android:toAlpha="1.0"/>

 <rotate android:fromDegrees="0"
  android:toDegrees="360"
  android:pivotX="0"
  android:pivotY="0"
  android:repeatMode="restart"
  android:repeatCount="infinite"/>
</set>

第二步 :activity_main.xml ( 略 )

第三步 :MainActivity.java

package com.lyp.anim;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
 private Button btnScale;
 private Button btnRotate;
 private Button btnTranslate;
 private Button btnAlpha;
 private Button btnAll;

 private ImageView mImage;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 initView();
 }

 private void initView() {
 btnScale= (Button) findViewById(R.id.btn_scale);
 btnRotate= (Button) findViewById(R.id.btn_rotate);
 btnTranslate= (Button) findViewById(R.id.btn_translate);
 btnAlpha= (Button) findViewById(R.id.btn_alpha);
 btnAll= (Button) findViewById(R.id.btn_all);

 mImage= (ImageView) findViewById(R.id.image);

 btnScale.setOnClickListener(this);
 btnRotate.setOnClickListener(this);
 btnTranslate.setOnClickListener(this);
 btnAlpha.setOnClickListener(this);
 btnAll.setOnClickListener(this);
 }

 @Override
 public void onClick(View v) {
 switch (v.getId()){
  case R.id.btn_scale:
  //加載縮放動(dòng)畫(huà)
  Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
  scale.setFillAfter(true); //保留動(dòng)畫(huà)結(jié)束狀態(tài),在xml文件中設(shè)置無(wú)效!!
  mImage.startAnimation(scale);
  break;
  case R.id.btn_rotate:
  //加載旋轉(zhuǎn)動(dòng)畫(huà)
  Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
  mImage.startAnimation(rotate);
  break;
  case R.id.btn_translate:
  //加載位移動(dòng)畫(huà)
  Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
  mImage.startAnimation(translate);
  break;
  case R.id.btn_alpha:
  //加載透明度漸變動(dòng)畫(huà)
  Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
  mImage.startAnimation(alpha);
  break;
  case R.id.btn_all:
  //加載組合動(dòng)畫(huà)
  Animation all = AnimationUtils.loadAnimation(this, R.anim.all);
  mImage.startAnimation(all);
  break;
 }
 }
}

總結(jié)

以上Android中補(bǔ)間動(dòng)畫(huà)(Tween Animation)基礎(chǔ)的全部?jī)?nèi)容了,動(dòng)畫(huà)Animation實(shí)現(xiàn)的兩種方式小編現(xiàn)在已經(jīng)都給大家分享了,希望能對(duì)各位Android開(kāi)發(fā)者們有所幫助,如果有疑問(wèn)大家可以留言交流。

相關(guān)文章

最新評(píng)論