我创建了简单的视频查看应用程序,它工作正常。我已将 layoutparams 添加到视频视图并将 videoview 添加到一个布局位置,那时我的媒体控制器显示在该区域之外,但我希望在视频上显示媒体控制器。请给我您有用的建议。
截屏:
代码:
public class MainActivity extends Activity {
private VideoView view;
RelativeLayout layoutmain, layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layoutmain = (RelativeLayout) findViewById(R.id.id1);
MediaController controller = new MediaController(this);
view = new VideoView(this);
view.setVideoPath("/mnt/sdcard/jj.avi");
RelativeLayout.LayoutParams viewparam = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
viewparam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
viewparam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
viewparam.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
viewparam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
view.setLayoutParams(viewparam);
FrameLayout.LayoutParams viewparam1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
controller.setLayoutParams(viewparam1);
view.setMediaController(controller);
controller.setAnchorView(controller);
view.requestFocus();
view.start();
try {
layout = new RelativeLayout(this);
RelativeLayout.LayoutParams viewparam2 = new RelativeLayout.LayoutParams(500, 500);
viewparam2.setMargins(20, 20, 0, 0);
layout.setLayoutParams(viewparam2);
layout.setBackgroundColor(Color.BLACK);
layout.addView(view);
layout.addView(controller);
} catch (Exception e) {
e.printStackTrace();
}
layoutmain.addView(layout);
}
}