gpt4 book ai didi

android - 如何动画更改 VideoView 的大小?

转载 作者:行者123 更新时间:2023-11-30 01:04:05 27 4
gpt4 key购买 nike

我有一个 VideoView,我想在我的应用程序中动态更改它的大小。通过扩展 VideoView 类,我已经成功地让 video 和 videoView 正确地改变了大小。但是,我希望能够在两种尺寸之间逐渐过渡。我怎样才能做到这一点?我试过缩放动画,但虽然这会改变 VideoView 布局的大小,但视频本身不会缩放。想法?

这是我的视频课:

public class MyVideoView extends VideoView {

private int mForceHeight,mForceWidth;
private int mOrigWidth, mOrigHeight, mMinWidth, mMinHeight;


public MyVideoView(Context context) {
super(context);
}

/* Will cause inflator errors if not present */
public MyVideoView(Context context, AttributeSet attrs){
super(context, attrs);
}

public void setDimensions(int w, int h) {
this.mForceHeight = h;
this.mForceWidth = w;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

if (mForceHeight != 0)
setMeasuredDimension(mForceWidth, mForceHeight);
else
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}


public void setOrigDimens(int width, int height) {
mOrigWidth = width;
mOrigHeight = height;

mMinWidth = width/4; // My own decision for the small size
mMinHeight = height/4;
}


public void setSmallView() {
setNewViewSize(mMinWidth, mMinHeight);
}


public void setNormalView() {
setNewViewSize(mOrigWidth, mOrigHeight);
}


/* RESIZES THE VIEW */
public void setNewViewSize(int width, int height) {
mForceWidth = width;
mForceHeight = height;
setDimensions(width, height);
getHolder().setFixedSize(width, height);
}
}

这是我试过的缩放代码:

Animation scaling = new ScaleAnimation(1.0f, 0.2f, 1.0f, 0.2f);
scaling.setDuration(2000);
startAnimation(scaling);

非常感谢任何帮助!

最佳答案

我找到的一个解决方案是使用 ValueAnimator 来更改大小的比例,然后使用更新监听器强制视频实际更改大小。然而,它非常紧张:

ValueAnimator scaleDown = ValueAnimator.ofFloat(1, 0.25f);
scaleDown.setDuration(1000);

scaleDown.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
setNewViewSize(mOrigWidth*value, mOrigHeight*value);
}
});

scaleDown.start();

关于android - 如何动画更改 VideoView 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39049526/

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