I am trying to use an animation for that hides and shows a toolbar
by detecting swiping gestures.It works but the issue is that when the toolbar
is there(visible) it will repeat if you swipe up again and again and again. How can I prevent this from happening? I've try using variable to count each step then reset at the ending but that does not work either. Helping me past this would save a lot more time I've been stuck here for 2 weeks now.
CoreActivity.java
//Swipe Events WebSwipe
WebSwipe = new Swipe(350, 700);
WebSwipe.setListener(new SwipeListener() {
@Override
public void onSwipingLeft(final MotionEvent event) {
}
@Override
public void onSwipedLeft(final MotionEvent event) {
}
@Override
public void onSwipingRight(final MotionEvent event) {
}
@Override
public void onSwipedRight(final MotionEvent event) {
}
@Override
public void onSwipingUp(final MotionEvent event) {
}
@Override
public void onSwipedUp(final MotionEvent event) {
Animation ToolbarGone = AnimationUtils.loadAnimation(CoreActivity.this, R.anim.m_toolbar_gone);
m_Toolbar.startAnimation(ToolbarGone);
}
@Override
public void onSwipingDown(final MotionEvent event) {
}
@Override
public void onSwipedDown(final MotionEvent event) {
Animation ToolbarVisible = AnimationUtils.loadAnimation(CoreActivity.this, R.anim.m_toolbar_visible);
m_Toolbar.startAnimation(ToolbarVisible);
}
});
}
Use visibility
of view
if it is visible
don't start animation.
Use animation listeners
, so that you can set your view visibility
to GONE
Try this code::
Add boolean
to manage swipe gesture.
private boolean isSwipeUp=falese;
//Swipe Events WebSwipe
WebSwipe = new Swipe(350, 700);
WebSwipe.setListener(new SwipeListener() {
@Override
public void onSwipingLeft(final MotionEvent event) {
}
@Override
public void onSwipedLeft(final MotionEvent event) {
}
@Override
public void onSwipingRight(final MotionEvent event) {
}
@Override
public void onSwipedRight(final MotionEvent event) {
}
@Override
public void onSwipingUp(final MotionEvent event) {
}
@Override
public void onSwipedUp(final MotionEvent event) {
if(!isSwipeUp)
{
Animation ToolbarGone = AnimationUtils.loadAnimation(CoreActivity.this, R.anim.m_toolbar_gone);
m_Toolbar.startAnimation(ToolbarGone);
isSwipeUp = true;
}
}
@Override
public void onSwipingDown(final MotionEvent event) {
}
@Override
public void onSwipedDown(final MotionEvent event) {
Animation ToolbarVisible = AnimationUtils.loadAnimation(CoreActivity.this, R.anim.m_toolbar_visible);
m_Toolbar.startAnimation(ToolbarVisible);
isSwipeUp = false;
}
});
}
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.