【问题标题】:Dialogfragment dynamic grow animation on image item clickDialogfragment 在图像项单击时动态增长动画
【发布时间】:2016-12-20 12:12:08
【问题描述】:

我使用网格布局管理器创建了 recyclerview。当任何人单击图像缩略图时,该图像应在 Dialogfragment 中展开为全屏,其中具有视图寻呼机,其中包含单击拇指的动画。

我尝试了不同的解决方案,但没有奏效。从样式直接应用的动画,但是如何定义动态运行时动画。

我尝试了以下但不完全正常。

关于如何实现这件事的任何想法?

MediaFragment.java

@Override
public void onItemClick(View v, int position) {
    switch (v.getId()) {
        case R.id.llItemContainer:
            Bundle bundle = new Bundle();
            bundle.putInt(Constant.KEY_CURRENT_ITEM, position);
            dialogMediaProfileFragment = new DialogMediaProfileFragment();
            dialogMediaProfileFragment.setArguments(bundle);
            dialogMediaProfileFragment.show(getFragmentManager(), TAG);
            zoomImageFromThumb(v).start();
            break;
    }
}

private Animator zoomImageFromThumb(final View thumbView) {

    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    startBounds = new Rect();
    finalBounds = new Rect();
    Point globalOffset = new Point();

    thumbView.getGlobalVisibleRect(startBounds);
    rvMediaPost.getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    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;
    }
    setAlpha(thumbView, 1f);
    //This shows the nullpointer exception

    /*setPivotX(dialogMediaProfileFragment.getView(), 0f);
    setPivotY(dialogMediaProfileFragment.getView(), 0f);*/

    AnimatorSet set = new AnimatorSet();
    set.play(
            ObjectAnimator.ofFloat(dialogMediaProfileFragment, "translationX",
                    startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(dialogMediaProfileFragment, "translationY",
                    startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(dialogMediaProfileFragment, "scaleX",
                    startScale, 1f))
            .with(ObjectAnimator.ofFloat(dialogMediaProfileFragment, "scaleY",
                    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;
        }
    });
    return mCurrentAnimator = set;

}

private void setAlpha(View view, float alpha) {
    view.setAlpha(alpha);
}

private void setPivotX(View view, float x) {
    view.setPivotX(x);
}

private void setPivotY(View view, float y) {
    view.setPivotY(y);
}

【问题讨论】:

    标签: java android animation dialogfragment


    【解决方案1】:

    @Jaymin Panchal,

    你必须实现自定义Android Activity Transition animation

    您也可以参考 this code snippet 了解有关您的要求的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      相关资源
      最近更新 更多