Android 4種アニメ
8923 ワード
!!5.0遷移アニメーションの追加
1.属性アニメーション
!!コントロールの実際の値を変更する
1.1 Xml ObjectAnimatorを使用してコードを呼び出す
1.2コード制御属性アニメーション
PropertyValuesHolderを使用して複数の状態効果を格納するAnimatorSetのplayTogetherを使用しても実現できますし、Setは再生順序をafter、beforeまたは集合playSequentiallyで制御できます
2.補間アニメーション
~1.AnimationSetで各種Animationを保存しanimフォルダXMLにロードする scale,translate,alpha,ratate
package com.xiaowu.interpolatoranim;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.transition.TransitionSet; import android.util.TypedValue; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.ImageView;
public class MainActivity extends AppCompatActivity { private ImageView iv; private Animation mAnimation; private AnimationSet set; private int res;
}
3.フレームアニメーション
AnimationDrawableを使用してDrawableフォルダに画像を設定backGround!!srcを使わないで
xmlロード:Animation_を使用するList item画像と継続時間の設定
4.トランジションアニメーション
トランジションアニメーションをサポートするプロパティをstyleに追加通常アニメーション(サポート効果)1.フェードアウト2.スライドSlide 3.分解Explode xmlレイアウトtransitionファイル申明XMLファイルに設定上の属性、追加時間、補間器などのxmlまたはjavaコード設定は、ジャンプActivityでStartActivityのoptions属性を使用する必要があります.そうしないと、遷移アニメーションstartActivity(intent,Activity Options.makeSceneTransitionAnimation)はありません.toBundle());//通常のジャンプ アニメーションセットで共有要素アニメーション1.changeBounds:ターゲットビューのレイアウト境界を変更します.2.changeClipBounds:ターゲットビューの境界を切り取ります.3.changeTransform:ターゲットのスケールと回転角度を変更します.4.changeImageTransform:ターゲットピクチャのサイズとスケールを変更します.
共有要素ジャンプ:1つの共有要素を持つ2つのactivities間で遷移アニメーションを使用するには:1.あなたの遷移アニメーションをXMLリソース2として定義します.トピックでウィンドウのコンテンツ遷移を有効にします.トピックスタイルで共有要素の遷移を指定します.
4.android:transitionNameプロパティを使用して、2つのレイアウトの共有要素に同じ名前を指定します(名前は必ず書き間違えないでください).
5.Activity Optionsを使用する.makeSceneTransitionAnimation()メソッド
//ジャンプ共有
常用windowクラス
共有要素
1.属性アニメーション
!!コントロールの実際の値を変更する
1.1 Xml ObjectAnimatorを使用してコードを呼び出す
public void click(View view) {
if (animator == null) {
animator = AnimatorInflater.loadAnimator(this,R.animator.my_scale);//
animator.setDuration(3000);
animator.setTarget(iv);//
animator.start();//
}
}
1.2コード制御属性アニメーション
ObjectAnimator animator = ObjectAnimator.ofFloat(iv,"alpha",0,1);
PropertyValuesHolderを使用して複数の状態効果を格納するAnimatorSetのplayTogetherを使用しても実現できますし、Setは再生順序をafter、beforeまたは集合playSequentiallyで制御できます
2.補間アニメーション
~1.AnimationSetで各種Animationを保存しanimフォルダXMLにロードする
package com.xiaowu.interpolatoranim;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.transition.TransitionSet; import android.util.TypedValue; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.ImageView;
public class MainActivity extends AppCompatActivity { private ImageView iv; private Animation mAnimation; private AnimationSet set; private int res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
set = new AnimationSet(true);
// mAnimation.setDuration(6000);
// animation.start();
}
public void click(View view) {
switch (view.getId()) {
case R.id.btn_01://xml
mAnimation = AnimationUtils.loadAnimation(this, R.anim.my_alpha);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setRepeatCount(Animation.INFINITE);
iv.startAnimation(mAnimation);
break;
case R.id.btn_02://xml
mAnimation = AnimationUtils.loadAnimation(this, R.anim.my_rotate);
iv.startAnimation(mAnimation);
break;
case R.id.btn_03://xml
mAnimation = AnimationUtils.loadAnimation(this, R.anim.my_translate);
mAnimation.setDuration(1000);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setRepeatCount(-1);
iv.startAnimation(mAnimation);
break;
case R.id.btn_04://xml
mAnimation = AnimationUtils.loadAnimation(this, R.anim.my_scale);
mAnimation.setDuration(1000);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setRepeatCount(-1);
iv.startAnimation(mAnimation);
break;
case R.id.btn_05://xml
mAnimation = AnimationUtils.loadAnimation(this, R.anim.my_set);
mAnimation.setDuration(1000);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setRepeatCount(-1);
iv.startAnimation(mAnimation);
break;
case R.id.btn_06://
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
alphaAnimation.setDuration(3000);
alphaAnimation.setRepeatCount(Animation.INFINITE);
alphaAnimation.setRepeatMode(Animation.REVERSE);
alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 3.3f, 2f, .5f, .5f, .5f);
scaleAnimation.setDuration(6000);
scaleAnimation.setRepeatCount(Animation.INFINITE);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
TranslateAnimation translateAnimation = new TranslateAnimation(0, 200, 0, 200);
translateAnimation.setDuration(2000);
translateAnimation.setRepeatCount(Animation.INFINITE);
translateAnimation.setRepeatMode(Animation.REVERSE);
translateAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
RotateAnimation rotateAnimation = new RotateAnimation(360, -270, 0.5f, 0.5f);
rotateAnimation.setDuration(4500);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setRepeatMode(Animation.REVERSE);
rotateAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
switch (res) {
case 0:
set.addAnimation(alphaAnimation);
set.addAnimation(scaleAnimation);
set.addAnimation(translateAnimation);
set.addAnimation(rotateAnimation);
iv.startAnimation(set);
res++;
break;
case 1:
iv.clearAnimation();// ImageView
set.getAnimations().clear();// , onClick Set
res++;
break;
case 2:
set.addAnimation(alphaAnimation);
set.addAnimation(scaleAnimation);
set.addAnimation(translateAnimation);
set.addAnimation(rotateAnimation);
iv.startAnimation(set);
res--;
break;
}
}
}
}
3.フレームアニメーション
AnimationDrawableを使用してDrawableフォルダに画像を設定backGround!!srcを使わないで
xmlロード:Animation_を使用するList item画像と継続時間の設定
4.トランジションアニメーション
トランジションアニメーションをサポートするプロパティをstyleに追加
TransitionSet set = new TransitionSet()
.addTransition(new Scale(0.7f))
.addTransition(new Fade())
.setInterpolator(visible ? new LinearOutSlowInInterpolator() :
new FastOutLinearInInterpolator());
TransitionManager.beginDelayedTransition(transitionsContainer, set);
Recolorカラーランプを使用してsetBackgroundColorの背景色を通過した場合、アニメーション効果はありません.setBackground、setBackgroundDrawable を使用できます.共有要素ジャンプ:1つの共有要素を持つ2つのactivities間で遷移アニメーションを使用するには:1.あなたの遷移アニメーションをXMLリソース2として定義します.トピックでウィンドウのコンテンツ遷移を有効にします.トピックスタイルで共有要素の遷移を指定します.
4.android:transitionNameプロパティを使用して、2つのレイアウトの共有要素に同じ名前を指定します(名前は必ず書き間違えないでください).
5.Activity Optionsを使用する.makeSceneTransitionAnimation()メソッド
//ジャンプ共有
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this,view,"shareName").toBundle());
常用windowクラス
requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
setExitTransition() - A B , A View transition
setEnterTransition() - A B , B View transition
setReturnTransition() - B A , B View transition
setReenterTransition() - B A , A View transition
setSharedElementEnterTransition(); ,A->B,B
setSharedElementExitTransition(); ,A->B,A
setSharedElementReenterTransition(); ,B->A,A
setSharedElementReturnTransition(); ,B->A,B
共有要素
ChangeBounds - layout bound, layout bound 。ChangeBounds , activity 。
ChangeTransform - (scale) (rotation) , (scale) (rotation) 。
ChangeClipBounds - clip bounds, clip bounds 。
ChangeImageTransform - (ImageView) transform matrices , ImageViewtransform matrices 。 ChangeBounds , ImageView , ImageView.ScaleType 。