我的过渡不起作用,我不知道我错过了什么或做错了什么。 我想实现一个EnterTransition,Detail Activity启动一个Fragment。
public class DetailActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
if (savedInstanceState == null) {
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
Integer integer=(Integer)bundle.get("movieId");
bundle.putString("movieId",String.valueOf(integer));
DetailActivityFragment detailActivityFragment=new DetailActivityFragment();
detailActivityFragment.setArguments(bundle);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) {
addEnterTransitionV21(detailActivityFragment);
}
getSupportFragmentManager().beginTransaction()
.add(R.id.detail_activity_container,detailActivityFragment)
// .add(R.id.container, new DetailFragment())
.commit();
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void addEnterTransitionV21(Fragment fragment) {
Slide slideTransition = new Slide(Gravity.LEFT);
slideTransition.addTarget(R.id.content_transition);
slideTransition.setInterpolator(AnimationUtils.loadInterpolator(this,
android.R.interpolator.linear_out_slow_in));
slideTransition.setDuration(1000);
fragment.setEnterTransition(slideTransition);
}
任何帮助将不胜感激。提前谢谢。