Использование ObjectAnimator для трансляции вида, но не работает - PullRequest
0 голосов
/ 07 октября 2018

Я использую следующий код для перевода изображения в определенную точку x & y на экране.

private void makeCircle() {
        ObjectAnimator cornerAnimation =
                ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", 500.0f);

        Animator shiftAnimation = AnimatorInflater.loadAnimator(this, R.animator.slide_up_left);
        shiftAnimation.setTarget(mParent);
        Log.d("TESTING","oy : "+oy);
        ObjectAnimator oax = ObjectAnimator.ofFloat(mParent, "x", ox);
        ObjectAnimator oay = ObjectAnimator.ofFloat(mParent, "y", oy);
        ValueAnimator anim = ValueAnimator.ofInt(ch, oh);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
                layoutParams.height = val;
                imageView.setLayoutParams(layoutParams);
                layoutParams = mParent.getLayoutParams();
                layoutParams.height = val;
                mParent.setLayoutParams(layoutParams);
            }
        });
        ValueAnimator anim2 = ValueAnimator.ofInt(cw, ow);
        anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = mParent.getLayoutParams();
                layoutParams.width = val;
                mParent.setLayoutParams(layoutParams);
                layoutParams = imageView.getLayoutParams();
                layoutParams.width = val;
                imageView.setLayoutParams(layoutParams);
            }
        });
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(300);
        animatorSet.playTogether(cornerAnimation, shiftAnimation,oax,oay,anim,anim2);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                    public void onGlobalLayout() {
                        int ch = imageView.getHeight();
                        int cw = imageView.getWidth();
//                x = imageView.getLeft();
//                y = imageView.getTop();
                        imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        int[] locations = new int[2];
                        imageView.getLocationOnScreen(locations);
                        int cx = locations[0];
                        int cy = locations[1];
                        // don't forget to remove the listener to prevent being called again
                        // by future layout events:
                        Log.d("TEST2", "cx:"+cx+",cy:"+cy+",cw:"+cw+",ch:"+ch);
                    }
                });
//                dismiss();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorSet.start();
        Log.d("VIEWPROFILEPICTUREACT", "ox:"+ox+",oy:"+oy+",ow:"+ow+",oh:"+oh);
        Log.d("VIEWPROFILEPICTUREACT", "cx:"+cx+",cy:"+cy+",cw:"+cw+",ch:"+ch);
    }

Значение, которое я получаю в журнале "TEST2" и других журналах, показано ниже:

ИСПЫТАНИЕ: oy: 276 ПРОСМОТР ФИЛЬМА: ox: 62, oy: 276, ow: 197, oh: 199 VIEWPROFILEPICTUREACT: cx: 277, cy: 666, cw: 525, ch: 525 TEST2: cx:63, cy: 340, cw: 197, ch: 199

Почему в коде я прошу перевести на 276 лет, а только на 340?

...