我有一个包含Imageview的布局,方法是单击Imageview 使用隐藏布局以全屏显示Imageview。 单击后我正在使用放大视图动画。一旦隐藏布局 出现向上滑动以关闭隐藏的布局。
隐藏布局第一次出现没有问题,但是出现了 第二次隐藏的布局未显示,仅当我尝试滑动时才会显示 起来
布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<!-- The views behind the draggable layout =================== -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginRight="1dp"
android:layout_marginEnd="1dp"
android:src="@drawable/place"
android:scaleType="centerCrop"
android:contentDescription="des"/>
</LinearLayout>
<!-- =================== The views behind the draggable layout -->
<!-- the dragging and related views ========================== -->
<ImageView
android:id="@+id/imgDarkOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e0000000"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/linDraggable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cblack"
android:clickable="true"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/expanded_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:background="@color/cblack"
android:src="@drawable/place"/>
</LinearLayout>
<View
android:id="@+id/viewTouchListener"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
<!-- ========================== the dragging and related views -->
</FrameLayout>
点击监听器
private void onClicks() {
zoomImageFromThumb(image, "http://fuddict.com/images/33.png");
}
});
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
}
private void zoomImageFromThumb(ImageView image, String s)
{
if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); }
Glide.with(this).load(s).apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.ALL)).into(expanded_image);
final Rect startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
image.getGlobalVisibleRect(startBounds);
findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y);
float startScale;
if ((float) finalBounds.width() / finalBounds.height()
> (float) startBounds.width() / startBounds.height()) {
// Extend start bounds horizontally
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
// Extend start bounds vertically
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
}
image.setAlpha(0f);
viewTouchListener.setVisibility(View.VISIBLE);
linDraggable.setVisibility(View.VISIBLE);
imgDarkOverlay.setVisibility(View.VISIBLE);
expanded_image.setPivotX(0f);
expanded_image.setPivotY(0f);
AnimatorSet set = new AnimatorSet();
set
.play(ObjectAnimator.ofFloat(expanded_image, View.X,
startBounds.left, finalBounds.left))
.with(ObjectAnimator.ofFloat(expanded_image, View.Y,
startBounds.top, finalBounds.top))
.with(ObjectAnimator.ofFloat(expanded_image, View.SCALE_X,
startScale, 1f))
.with(ObjectAnimator.ofFloat(expanded_image,
View.SCALE_Y, startScale, 1f));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentAnimator = null;
}
@Override
public void onAnimationCancel(Animator animation) {
mCurrentAnimator = null;
}
});
set.start();
mCurrentAnimator = set;
getHeight();
}
在向上滑动时会发生这种情况:
private void runFinishingCode() {
image.setAlpha(1f);
viewTouchListener.setVisibility(View.GONE);
linDraggable.setVisibility(View.GONE);
imgDarkOverlay.setVisibility(View.GONE);
mCurrentAnimator=null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.parseColor("#000000"));
}
}
为什么隐藏的布局动画第二次不起作用?的 隐藏布局仅在向上滑动后出现。