gpt4 book ai didi

android - ScaleAnimation后如何获取View的新宽高

转载 作者:行者123 更新时间:2023-11-29 02:09:44 30 4
gpt4 key购买 nike

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

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

最佳答案

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

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


}

});

关于android - ScaleAnimation后如何获取View的新宽高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164685/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com