ScaleAnimation后如何获取View新的宽高

发布于 2024-12-16 00:27:18 字数 791 浏览 6 评论 0原文

我使用 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

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

I used a ScaleAnimation to resize my ImageView. But after the animation is complete, how can I get the dimension of my ImageView or the bitmap in that.
Thanks

Here is my code:

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);

Where m_oldZoomRatio != m_currentZoomRatio.

I can see my view changes its layout while running. But when get its width and height, I receive the value in original when the view is created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-12-23 00:27:18

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

  <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) {


        }

     });

try to use animation listener where on animation end you can change the width and height

  <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) {


        }

     });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文