A笔记
代码记录:
fragment_cont_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="1280"
android:valueTo="0"
android:duration="200"/>
</set>
fragment_cont_out.xml
<?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:propertyName="x" android:valueType="floatType" android:valueFrom="0" android:valueTo="1280" android:duration="200"/> </set>
fragment_main_in.xml
<?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:propertyName="scaleX" android:valueFrom="0.8" android:valueTo="1" > </objectAnimator> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:propertyName="scaleY" android:valueFrom="0.8" android:valueTo="1" > </objectAnimator> </set>
fragment_main_out.xml
<?xml version="1.0" encoding="utf-8"?> <set> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:propertyName="scaleX" android:valueFrom="1" android:valueTo="0.8" > </objectAnimator> <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:propertyName="scaleY" android:valueFrom="1" android:valueTo="0.8" > </objectAnimator> </set>
file
public void switchContent(Fragment from, Fragment to) { FragmentManager fm = getFragmentManager(); // 开启Fragment事务 // FragmentTransaction transaction = fm.beginTransaction(); if (mCurFragment != to) { mCurFragment = to; FragmentTransaction transaction = fm.beginTransaction(); if(mCurFragment==mMain) { transaction.setCustomAnimations(R.animator.fragment_main_in, R.animator.fragment_cont_out); } else { transaction.setCustomAnimations(R.animator.fragment_cont_in, R.animator.fragment_main_out); } // .setCustomAnimations( // android.R.anim.fade_in, R.anim.); Log.i("testFile", "to.isAdded()" + !to.isAdded()); if (!to.isAdded()) { // 先判断是否被add过 transaction.hide(from).add(R.id.container_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中 } else { transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个 } } }
lol:http://lol.qq.com/act/a20120723awards/index.html
ok
浙公网安备 33010602011771号