Issue
I'm trying to program the Android's back button to have the opposite sliding effect when pressed.
I have MainActivity(a), and pressing something creates yet another MainActivity(b) (and setting different content programatically). Going from MainActivity(a) to MainActivity(b) is sliding in from the right (and out to the left) which is correct.
However, when I click on the Back button, it should slide in from the left and (out to the right) - ie. the opposite - but the effect is the same as the above. I want to have the animation that pressing the back brings back the previous screen (from the left)
Here's my code:
@Override
public void onIndexFragmentInteraction(final IndexesRecyclerViewAdapter.ViewHolder viewHolder) {
final Context thisContext = this;
YoYo.with(Techniques.Pulse).onEnd(new YoYo.AnimatorCallback() {
@Override
public void call(Animator animator) {
CelebritiesFragment celebritiesFragment = new CelebritiesFragment();
celebritiesFragment.setIndex(viewHolder.index);
CelebritiesTabViewsStack.getInstance().push(celebritiesFragment);
Intent intent = new Intent(thisContext, MainActivity.class);
startActivity(intent);
}
}).delay(0).duration(250).playOn(viewHolder.mView);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.animator.slide_in_right, R.animator.slide_out_left);
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.animator.slide_out_left, R.animator.slide_out_right);
// no effect, even if I use overridePendingTransition(0, 0);
}
I guess the problem is both are the the same MainActiity class. How to resolve this problem?
Solution
After much experiment, I found the solution myself:
@Override
public void onIndexFragmentInteraction(final IndexesRecyclerViewAdapter.ViewHolder viewHolder) {
final Context thisContext = this;
YoYo.with(Techniques.Pulse).onEnd(new YoYo.AnimatorCallback() {
@Override
public void call(Animator animator) {
CelebritiesFragment celebritiesFragment = new CelebritiesFragment();
celebritiesFragment.setIndex(viewHolder.index);
CelebritiesTabViewsStack.getInstance().push(celebritiesFragment);
Intent intent = new Intent(thisContext, MainActivity.class);
//finish();
startActivity(intent);
overridePendingTransition(R.animator.slide_in_right, R.animator.slide_out_left);
}
}).delay(0).duration(250).playOn(viewHolder.mView);
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(0, R.animator.slide_out_right);
}
Answered By - ikevin8me
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.