0

首次工具栏动画效果不错,工具栏成功地在屏幕外动画。使用ViewPropertyAnimator工具栏动画不能第二次工作

问题:工具栏上的动画不能用于点击任何视图,工具栏不会通过动画重新出现在屏幕上。活动

XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_image_viewer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.v4.view.ViewPager 
    android:id="@+id/activity_image_viewer_view_pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/black" /> 

<include 
    android:id="@+id/toolbar" 
    layout="@layout/toolbar" /> 

</RelativeLayout> 

工具栏的代码是:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary"> 

</android.support.v7.widget.Toolbar> 

活动代码:IN的onCreate,这将隐藏状态栏,导航栏和工具栏

RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) toolbar.getLayoutParams(); 
    layoutParams.setMargins(0, uiUtils.getStatusBarHeight(getResources()), 0, 0); 
    toolbar.setLayoutParams(layoutParams); 

toolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
     @Override 
     public void onGlobalLayout() { 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 
       toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start(); 
      } 
      uiUtils.hideStatusNavigationBar(getWindow()); 

      ViewTreeObserver observer = toolbar.getViewTreeObserver(); 
      if (observer.isAlive()) { 
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 
        observer.removeOnGlobalLayoutListener(this); 
       } else { 
        observer.removeGlobalOnLayoutListener(this); 
       } 
      } 
     } 
    }); 

下面是有问题的代码,工具栏esn't通过动画重新出现在任何视图中的点击(OnClickListener已经设置视图)

@Override 
public void onClick(View view) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 
     toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start(); 
    } 
    uiUtils.showStatusNavigationBar(getWindow()); 
} 
+0

您必须先隐藏工具栏。例如: toolbar.animate()。translationY(-toolbar.getHeight())。start(); – Harry

+0

对不起,兄弟,我已经更新了行代码。我改变了测试不同的标准。 –

回答

0

通过的错误,我已经设置ViewPager的OnClickListener,现在我已经意识到的onClick()方法永远不会是呼吁寻呼机。 这就是为什么工具栏重新出现动画不起作用。

有时我们不介意很简单的事情。

解决方案:从ViewPager中删除OnClickListener并将其设置为其他可单击的视图。