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());
}
您必須先隱藏工具欄。例如: toolbar.animate()。translationY(-toolbar.getHeight())。start(); – Harry
對不起,兄弟,我已經更新了行代碼。我改變了測試不同的標準。 –