横向模式下居中视频视图
如何在横向模式下将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其放入
LinearLayout
中,并将其重力设置为CENTER
,或者将CENTER_IN_PARRENT
放入addRule()RelativeLayout
的 code> 方法 :)祝你好运!
You can put it in a
LinearLayout
instead and set it's gravity toCENTER
, or just putCENTER_IN_PARRENT
in youraddRule()
method ofRelativeLayout
:)Good luck!