ScaleAnimation后如何获取View的新宽度和高度 [英] How to get the new width and height of View after ScaleAnimation
本文介绍了ScaleAnimation后如何获取View的新宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了ScaleAnimation
来调整ImageView
的大小.但是动画制作完成后,如何获得ImageView
或其中的位图的尺寸.
谢谢
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
这是我的代码:
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 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.
推荐答案
尝试使用动画侦听器,在动画结束时可以更改宽度和高度
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) {
}
});
这篇关于ScaleAnimation后如何获取View的新宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文