在运行时平移视频

时间:2010-07-22 03:53:39

标签: android video

我想让视图在屏幕上移动。那可能吗?

换句话说,我希望平移是可能的,我认为这与视图有关。

如何平移视频预览?

1 个答案:

答案 0 :(得分:1)

如果您想在整个屏幕上移动视图,则可能。假设这确实是你的要求,这就是你能做的。使视图成为相对布局的子项。每次要移动视图时,获取子视图的RelativeLayout.LayoutParams,更改相关边距并将其设置为子视图的LayoutParam。

如果您正在对SurfaceView执行此操作(需要播放视频),则每次更改边距时都会获得surfaceChanged回调。

这是我为API Demos的CameraPreview活动做的调整的示例代码,它也是如此。 SurfaceView从左向右移动。希望这会有所帮助。

此致 Anirudh。

public class CameraPreview extends Activity {
protected static final String TAG = "CameraPreview";
private Preview mPreview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Hide the window title.
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Create our Preview view and set it as the content of our activity.
    mPreview = new Preview(this);
    mPreview.setId(100);
    RelativeLayout mainLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams mainLp = new RelativeLayout.LayoutParams(640, 480);
    mainLp.leftMargin = 20;

    mainLayout.addView(mPreview, mainLp);

    Button btn = new Button(this);
    btn.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
            RelativeLayout.LayoutParams nLp = (LayoutParams) mPreview.getLayoutParams();
            nLp.leftMargin += 10;
            Log.v(TAG,"nLp.leftMargin: " + nLp.leftMargin);
            mPreview.setLayoutParams(nLp);
        }

    });
    btn.setText("Click me!");

    RelativeLayout.LayoutParams btnLp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    btnLp.addRule(RelativeLayout.BELOW, mPreview.getId());

    mainLayout.addView(btn ,btnLp);
    setContentView(mainLayout);
}

}