I am trying to run an animation on navigation drawer open on one of my views, following is my code:
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
System.out.println("Called");
ObjectAnimator animation = ObjectAnimator.ofInt(pw, "progress", 200);
animation.setDuration(1000);
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
// mDrawerList.setLayoutAnimation(getMaximAnim());
invalidateOptionsMenu();
}
};
The console prints Called
twice whenever I open the drawer, which means the animation will happen twice and it jitters this way. I want to animate the view only once, Where am I going wrong, any hints?
This is my drawerSlide code:
public void onDrawerSlide(View drawerView, float slideOffset) {
if(slideOffset > .55 && !drawerOpen){
onDrawerOpened(drawerView);
drawerOpen = true;
} else if(slideOffset < .45 && drawerOpen) {
onDrawerClosed(drawerView);
drawerOpen = false;
}
}
I have taken reference from here
You don't need
onDrawerOpened(drawerView);
in your onDrawerSlide. It's called by Android itself. As for changing titles, look at this:
public void restoreActionBar(){
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
and set mTitle
to any String you like in another part of code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.