在UI布局
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
在java布局中
VideoView videoview=findViewById(R.id.video_view);
videoview.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.视频));
RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
videoview.setLayoutParams(layoutparams);
videoview.setOnCompletionListener(new MediaPlayer.OnCompletioneListener(){
@Override
public void onCompletion(MediaPlayer mediaPlayer){
videoview.start();
}
videoview.start();
//循环播放
});