在videoview上添加按钮全屏
Posted
技术标签:
【中文标题】在videoview上添加按钮全屏【英文标题】:Add button fullscreen on videoview 【发布时间】:2012-12-19 08:17:54 【问题描述】:我需要添加全屏观看视频的功能。
Videoview 是否只在他的控制面板上提供 3 个按钮 () (>>),因为它可以添加第四个按钮以全屏显示视频?
要全屏观看视频,只需将嵌入它的布局的参数更改为 fill_parent。
有什么想法吗?
谢谢
【问题讨论】:
【参考方案1】:最后我通过手动将按钮添加到相对布局来解决它:
LinearLayout lLinLayout = new LinearLayout(this);
lLinLayout.setId(1);
lLinLayout.setOrientation(LinearLayout.VERTICAL);
lLinLayout.setGravity(Gravity.CENTER);
lLinLayout.setBackgroundColor(Color.BLACK);
LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
lLinLayout.setLayoutParams(lLinLayoutParms);
this.setContentView(lLinLayout);
RelativeLayout lRelLayout = new RelativeLayout(this);
lRelLayout.setId(2);
lRelLayout.setGravity(Gravity.CENTER);
lRelLayout.setBackgroundColor(Color.BLACK);
android.widget.RelativeLayout.LayoutParams lRelLayoutParms =
new android.widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
lRelLayout.setLayoutParams(lRelLayoutParms);
lLinLayout.addView(lRelLayout);
mVideoView = new VideoView(this);
mVideoView.setId(3);
android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams =
new android.widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mVideoView.setLayoutParams(lVidViewLayoutParams);
lRelLayout.addView(mVideoView);
Button myButton = new Button(this);
myButton.setId(3);
android.widget.RelativeLayout.LayoutParams buttonParams =
new android.widget.RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
buttonParams.addRule(RelativeLayout.CENTER_IN_PARENT);
myButton.setLayoutParams(buttonParams);
myButton.setText("My Button!");
lRelLayout.addView(myButton);
【讨论】:
以上是关于在videoview上添加按钮全屏的主要内容,如果未能解决你的问题,请参考以下文章