如何在ScaleAnimation之后获取View的新宽度和高度

时间:2011-11-17 09:18:17

标签: android android-animation android-imageview

我使用ScaleAnimation来调整ImageView的大小。但是在动画完成后,我如何才能获得ImageView或位图的维度。 感谢

这是我的代码:

ScaleAnimation animation = new ScaleAnimation(m_oldZoomRatio, m_currentZoomRatio, m_oldZoomRatio, m_currentZoomRatio);

        animation.setFillAfter(true);
        animation.setFillEnabled(true);
        animation.setAnimationListener(new AnimationListener() {

            public void onAnimationStart(Animation animation) {
            }

            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
            }
        });
        m_child.startAnimation(animation);

m_oldZoomRatio != m_currentZoomRatio

我可以看到我的视图在运行时更改其布局。但是当获得它的宽度和高度时,我会在创建视图时收到原始值。

1 个答案:

答案 0 :(得分:1)

尝试使用动画侦听器在动画结束时可以更改宽度和高度

  <animation-object>.setAnimationListener(new AnimationListener() 
     {

        @Override
        public void onAnimationEnd(Animation arg0) {
            img.getWidth();
                img.getHeight();
                  //OR 
                 int h=img.getLayoutParams().height;
                 int w=img.getLayoutParams().width;
                // For changing actual height and width
             view.getLayoutParams().width = newWidth; 
               view.getLayoutParams().height =    newHeight; 
view.requestLayout();

        }

        @Override
        public void onAnimationRepeat(Animation arg0) {


        }

        @Override
        public void onAnimationStart(Animation arg0) {


        }

     });
相关问题