Android:在缩放视图后获取屏幕上的视图位置?

时间:2017-04-15 17:14:11

标签: java android view

所以我的问题是,在使用ScaleAnimation类进行缩放后,我需要相对于屏幕的视图位置。 getLocationOnScreen函数在缩放动画之前和之后返回相同的位置。它看起来像是未缩放的观点位置。 ScaleAnimation类是否会缩放旧视图但创建一个新视图?如果是这样的话你怎么能得到新视图的指针?

这是代码

public void scaleView(final View v, float startScale, float endScale) {
    Animation anim = new ScaleAnimation(
            startScale, endScale, // Start and end values for the X axis scaling
            startScale, endScale, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF,0f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, 0f); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    anim.setFillBefore(false);
    anim.setFillEnabled(true);
    anim.setDuration(500);
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            int [] location = new int[2];
            v.getLocationOnScreen(location);
            Log.e("ee","x:"+String.valueOf(location[0]));
            Log.e("ee","y:"+String.valueOf(location[1]));
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            int [] location = new int[2];
            v.getLocationOnScreen(location);
            Log.e("ee","x:"+String.valueOf(location[0]));
            Log.e("ee","y:"+String.valueOf(location[1]));
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    v.startAnimation(anim);
}

0 个答案:

没有答案