在Relativelayout中移动VideoView

时间:2012-09-21 00:42:01

标签: android android-videoview

我有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();

}

有时它会移动和缩放视频,但有时 - 只有视频背景,将视频本身留在原位。而且效果很慢。

0 个答案:

没有答案