1. 程式人生 > >為視訊新增縮放動畫

為視訊新增縮放動畫

觸發:

    VideoWrapper videoWrapper = new VideoWrapper();
    AnimatorSet set = new AnimatorSet();
    set.playTogether(
        ObjectAnimator.ofFloat(videoWrapper, "width", 0, 1100),
        ObjectAnimator.ofFloat(videoWrapper, "height", 0, 1100)
    );
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public
void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); } }); set.setDuration(500).start();

VideoWrapper類(mVideoViewSurfaceView為顯示視訊的View):

class VideoWrapper {
    private ViewGroup.LayoutParams params;
    VideoWrapper() {
        params = mVideoViewSurfaceView.getLayoutParams();
    }

    public
int getWidth() { return params.width; } public int getHeight() { return params.height; } public void setWidth(float w) { params.width = (int) w; mVideoViewSurfaceView.setLayoutParams(params); } public void setHeight(float h) { params
.height = (int) h; mVideoViewSurfaceView.setLayoutParams(params); } }