lgvalle/Material-Animations

Not Working!!

Opened this issue · 11 comments

s1mar commented

I'm doing this,it is not working for me,any pointers guys

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setEnterTransition();
        setExitTransition();
      
    }

    @TargetApi(21)
    private void setEnterTransition(){

        Fade fade_transition = new Fade();
        fade_transition.setDuration(1000);
        getWindow().setEnterTransition(fade_transition);
    }

    @TargetApi(21)
    private void setExitTransition(){

        Slide slide_transition = new Slide();
        slide_transition.setDuration(1000);
        getWindow().setExitTransition(slide_transition);
    }

Can you please provide more info? What is happening? What do you expect to happen?

My guess is that you are missing this in your styles.xml

<item name="android:windowContentTransitions">true</item

s1mar commented

@MarijanGazica I was setting the basic slide and fade transitions programmatically(no xml),but they aren't working,I see no effect

@s1mar even though you did it programmatically, you still, from my experience, need to add that flag. Also, which version of Android is running on your test device(s)?

@lgvalle @MarijanGazica the same happened with me. I have set animation via program way, setup flag <item name="android:windowContentTransitions">true</item and nothing. Either nexus 5x 7.0 or emulator 6p 6.0

Hello @s1mar I think you have to start the activity with this code

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);

startActivity(intent, options.toBundle());

@Davids89 Hey, I'm having the same issues, I got the enter animation to work by adding the startActivity parameter but my exit transitions still don't work. Do you know if there is anything else necessary?

pcg92 commented

@Davids89 its working with this solution, but on my back press my activity is full grey, without UI

s1mar commented

@Davids89
` @OverRide
protected void onCreate(@nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
setupWindowAnimations();
}

private void setupWindowAnimations() {
    Slide slide =(Slide) TransitionInflater.from(this).inflateTransition(R.transition.activity_slide);
    getWindow().setExitTransition(slide);
}

@Override
protected void onStart() {
    super.onStart();
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Splash.this);
    Intent intent = new Intent(this,Splash2.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent,options.toBundle());
}`

still not working.

@pcegarra try adding the FLAG_ACTIVITY_NO_HISTORY, this will prevent your activity from going into the back stack,hope it works for you

s1mar commented

I've followed every instruction available on the internet and still couldn't get it to work. What I've observed is that on a cold start,you just cant see the enter transition of our launcher activity.Also, ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(Splash.this); Intent intent = new Intent(this,Splash2.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent,options.toBundle());

if you use a transition activity code,android simply seems to skip through the transition effects and launch the next activity. I believe there is something that you're forgetting to mention or tell us @lgvalle

I'm having the same issues,setExitTransition(Slide)not working,but the enter return and reenter is working

public class OneActivity extends AppCompatActivity implements View.OnClickListener {
    private Button mBack;
    private Button mNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_one);
        setupWindowAnimations();
        mBack = findViewById(R.id.btn_back);
        mNext = findViewById(R.id.btn_next);
        mBack.setOnClickListener(this);
        mNext.setOnClickListener(this);
    }

    private void setupWindowAnimations() {
        Slide enter = new Slide();
        enter.setDuration(DURATION);
        enter.setSlideEdge(Gravity.RIGHT);
        enter.setInterpolator(new DecelerateInterpolator());

        Slide exit = new Slide();
        exit.setDuration(DURATION);
        exit.setSlideEdge(Gravity.LEFT);
        exit.setInterpolator(new DecelerateInterpolator());

        Slide reenter = new Slide();
        reenter.setSlideEdge(Gravity.LEFT);
        reenter.setDuration(DURATION);
        reenter.setInterpolator(new DecelerateInterpolator());

        Slide returnT = new Slide();
        returnT.setDuration(DURATION);
        returnT.setSlideEdge(Gravity.RIGHT);
        returnT.setInterpolator(new DecelerateInterpolator());

        getWindow().setReenterTransition(reenter);
        getWindow().setEnterTransition(enter);
        getWindow().setReturnTransition(returnT);
        getWindow().setExitTransition(exit);
        getWindow().setAllowEnterTransitionOverlap(true);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finishAfterTransition();
                break;
            case R.id.btn_next:
                Intent i = new Intent(this, TowActivity.class);
                startActivity(i, ActivityOptionsCompat.makeSceneTransitionAnimation(this).toBundle());
                break;
            default:

        }
    }
}

please help me,thanks!