0
我想,該片段創建活動後進入代替togheter動畫片段是錯誤的
我的代碼輸入
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentTransaction;
public class TranslucentActivity extends Activity {
//....
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.translucent);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
android.app.Fragment fragment = new ViewDetail();
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction ft = fragmentManager.beginTransaction();
//ft.setCustomAnimations(R.anim.trans_left_in,R.anim.trans_left_out);
ft.setCustomAnimations(R.animator.trans_left_in,R.animator.trans_left_out);// now work but is wrong the animation because enter with the activity
ft.addToBackStack(null);
ft.replace(R.id.container, fragment);
ft.commit();
fragmentManager.executePendingTransactions();
super.onResume();
}
}
trans_left_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="@android:integer/config_longAnimTime"/>
</set>
trans_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="@android:integer/config_longAnimTime"/>
</set>
什麼是您的API?檢查出來http://stackoverflow.com/questions/17760299/android-fragmenttransaction-custom-animation-unknown-animator-name-translate –
我的API是Android 4.4.2 –
而不是動畫,你需要創建'animator'文件夾和使用'R.animator.yourid' –