day 11新特性ノート(fragment animation)
5781 ワード
Fragment
// View Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
// View , , Fragment
View v = inflater.inflate(R.layout.fragment01, null);
return v;
}
// fragment
//new fragment
Fragment01 fg = new Fragment01();
FragmentManager fm = getFragmentManager();
//
FragmentTransaction ft = fm.beginTransaction();
// fragment id
ft.replace(R.id.fl, fg);
ft.commit();
ライフサイクル
低バージョン対応
アニメーション(Animation)
フレームアニメーション
1枚の画像を絶えず切り替えて、アニメーションの効果を形成します
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/g1" android:duration="200" />
<item android:drawable="@drawable/g2" android:duration="200" />
<item android:drawable="@drawable/g3" android:duration="200" />
</animation-list>
ImageView iv = (ImageView) findViewById(R.id.iv);
// imageView
iv.setBackgroundResource(R.drawable.animations);
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
//
ad.start();
補間アニメーション
// ,
TranslateAnimation ta = new TranslateAnimation(10, 150, 20, 140);
TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 2);
//
ta.setDuration(2000);
//
ta.setRepeatCount(1);
//
ta.setRepeatMode(Animation.REVERSE);
// ,
ta.setFillAfter(true);
//
iv.startAnimation(ta);
ScaleAnimation sa = new ScaleAnimation(0.1f, 4, 0.1f, 4);
透過性:
AlphaAnimation aa = new AlphaAnimation(0, 0.5f);
回転:
RotateAnimation ra = new RotateAnimation(20, 360);
RotateAnimation ra = new RotateAnimation(20, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//
AnimationSet set = new AnimationSet(false);
//
set.addAnimation(aa);
set.addAnimation(sa);
set.addAnimation(ra);
iv.startAnimation(set);
プロパティーアニメーション
シフト:
// get、set
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "translationX", 0, 100) ;
ズーム:
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "scaleY", 0.1f, 2);
透過性:
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "alpha", 0.1f, 1);
回転
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "rotation", 20, 270);
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "rotationY", 20, 180);
可変パラメータ
ObjectAnimator oa = ObjectAnimator.ofFloat(bt, "translationX", 0, 70, 30, 100) ;
すべてのアニメーションが飛び立つ
//
AnimatorSet set = new AnimatorSet();
//
set.setTarget(bt);
//
//set.playSequentially(oa, oa2, oa3, oa4);
//
set.playTogether(oa, oa2, oa3, oa4);
set.start();