横向模式下居中视频视图

发布于 2024-12-20 15:28:11 字数 1065 浏览 0 评论 0原文

如何在横向模式下将 VideoView 居中?我尝试了这个:在清单文件上我有:

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

在我的活动上我有这个代码:

RelativeLayout.LayoutParams lv= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
    lv.addRule(RelativeLayout.CENTER_HORIZONTAL);
    myVideoView = new VideoView(this);
    myVideoView.setLayoutParams(lv);
    myVideoView.setVideoPath(Environment
                        .getExternalStorageDirectory()
                        + "/BouyguesImages"
                        + "37" + "/" + "89Video");

    myVideoView.requestFocus();

并且这个VideoView我将其作为视图添加到RelativeLayout:

 rr = new RelativeLayout(this);
 rr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT));
 rr.setBackgroundColor(Color.WHITE);

我的代码的结果是我的视频仅在顶部播放屏幕,底部屏幕是白色的(相对布局的颜色)。我想让 VideoView 适合屏幕,因此在屏幕底部和屏幕顶部都有一小部分白色。如何做到这一点?

提前致谢。 :)

How can I center a VideoView in landscape mode? I tried this: on Manifest file I have :

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

and on my Activity I have this code:

RelativeLayout.LayoutParams lv= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
    lv.addRule(RelativeLayout.CENTER_HORIZONTAL);
    myVideoView = new VideoView(this);
    myVideoView.setLayoutParams(lv);
    myVideoView.setVideoPath(Environment
                        .getExternalStorageDirectory()
                        + "/BouyguesImages"
                        + "37" + "/" + "89Video");

    myVideoView.requestFocus();

and this VideoView I add it as a View to a RelativeLayout :

 rr = new RelativeLayout(this);
 rr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT));
 rr.setBackgroundColor(Color.WHITE);

The result of my code is that my video is playing only in the top part of the screen and at the bottom the screen is white (relativelayout's color). I want to fit the VideoView on screen, so to have a small part white on the bottom of the screen, and on top of the screen to. How to do this?

Thanks in advance. :)

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

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

发布评论

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

评论(1

嘿嘿嘿 2024-12-27 15:28:11

您可以将其放入 LinearLayout 中,并将其重力设置为 CENTER,或者将 CENTER_IN_PARRENT 放入 addRule()RelativeLayout 的 code> 方法 :)

祝你好运!

You can put it in a LinearLayout instead and set it's gravity to CENTER, or just put CENTER_IN_PARRENT in your addRule() method of RelativeLayout :)

Good luck!

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