运行时平移视频

发布于 2024-09-11 01:57:25 字数 78 浏览 3 评论 0原文

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

换句话说,我希望可以进行平移,并且我认为这与视图有关。

如何平移视频预览?

I want to make the view move around the screen. Is that possible?

in other words, I want panning to be possible and I think that has something to do with the view.

How do you do Panning a video preview?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬色的秋千 2024-09-18 01:57:25

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

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

下面是我为 API 演示的 CameraPreview 活动所做的调整的示例代码,它具有相同的功能。 SurfaceView 从左向右移动。希望这有帮助。

问候,
阿尼鲁德。

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);
}

}

If you want to move your view all over the screen, its possible. Presuming this is indeed your requirement, here's what you could do. Make the view a child of Relative Layout. Everytime you want to move the view, get the RelativeLayout.LayoutParams of the child view, change relevent margins and set this as the child view's LayoutParam.

If you are doing this to a SurfaceView (needed to play the video), you get surfaceChanged callback everytime you change the margin.

Here's a sample code of the tweak I did for API Demos' CameraPreview activity which does the same. The SurfaceView is moved from left to right. Hope this helps.

Regards,
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);
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文