How can I avoid that my permanently visible menu slides out with the rest of the layout when switching between activities?
I have a menu that is always visible, and the same for all activities. Is it possible to开发者_Go百科 avoid that the menu slides out along with the rest of the layout when launching a new activity? You can compare it to the way the tabwidget works, where the tabs remain in place while the rest of the layout switches
Is it possible to avoid that the menu slides out along with the rest of the layout when launching a new activity?
No, it's not possible. Everything within the current Activity
are about to close/hide/animate out when you are starting a new Activity
.
Consider the use of a Tab Layout
.
A couple of ways come to mind.
If you want to keep using activities, you could fake it by disabling their sliding animations. You would then have to manually do animations for the parts of the UI you want to slide in/out. I'm not sure how smooth this might look when going from one activity to the other.
Use Fragments and animate in/out the parts of the UI that are changing.
I would go the fragment route.
for reference sake:
if you use FLAG_ACTIVITY_REORDER_TO_FRONT, the FLAG_ACTIVITY_NO_ANIMATION will only work the first time the activity is created. Going to the activity back, will skip the onCreate where certainly the overridePendingTransition() method is called.
You should add "overridePendingTransition(0,0)" in your onResume and the animation will disappear for good.
public void launchSecondActivity(){
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
//this flag will lead to problem the second time
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
}
//add this to your activities to fix it
@Override
public void onResume() {
super.onResume();
overridePendingTransition(0,0);
}
精彩评论