1

我有带 VideoView 的 RelativeLayout,需要通过手势移动和缩放 videoView。

mAnimationLayout = new RelativeLayout(mContext);
mAnimationLayout.setOnTouchListener(new AnimationListener());
RelativeLayout.LayoutParams lpFill = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.MATCH_PARENT, 
    RelativeLayout.LayoutParams.MATCH_PARENT
);
mVideoView = new VideoView(mContext);
mVideoView.setVideoURI(mProduct.mAnimationVideos.get(0));
mVideoView.start();
mAnimationLayout.addView(mVideoView, lpFill);

然后我试图做到这一点:

private void moveVideo(float x, float y){

    int left = mVideoView.getLeft() + (int)x;
    int top = mVideoView.getTop() + (int)y;

    //mVideoView.layout(left, top, right, bottom);
    RelativeLayout.LayoutParams lp = (LayoutParams) mVideoView.getLayoutParams();
    lp.setMargins(left, top, 0,0);
    mVideoView.setLayoutParams(lp);
    //mVideoView.invalidate();

}
private void scaleVideo(float scale){

    RelativeLayout.LayoutParams lp = (LayoutParams) mVideoView.getLayoutParams();
    lp.width =(int) (mVideoView.getWidth() * scale);
    lp.height = (int) (mVideoView.getHeight() * scale);
    mVideoView.setLayoutParams(lp);
    //mVideoView.invalidate();

}

有时它会移动和缩放视频,但有时 - 只有视频背景,将视频本身留在原处。而且它的工作速度非常慢。

4

0 回答 0