Home > Mobile >  RelativeLayout add 2 VideoView level error
RelativeLayout add 2 VideoView level error

Time:01-14


The android: id="@ + id/layMain"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Android: orientation="vertical" & gt;



Private RelativeLayout layout;

@ Override
Protected void onCreate (@ Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Empty);
Layout=the findViewById (R.i d.l ayMain);
AddView ();
}

Private void addView () {

RelativeLayout. LayoutParams params1=new RelativeLayout. LayoutParams (RelativeLayout. LayoutParams. WRAP_CONTENT,
RelativeLayout. LayoutParams. WRAP_CONTENT);
Params1. Height=800;
Params1. Width=1080;
Params1. The setMargins (0, 100, 0, 0).
VideoView videoView1=new VideoView (this);
Uri uri1=Uri. Parse (Environment. External.getexternalstoragedirectory () + File. The separator +
"Ca0b8818341dd777b953017d731a22d1. Mp4");
VideoView1. SetVideoURI (uri1);
VideoView1. SetOnPreparedListener (new MediaPlayer. OnPreparedListener () {
@ Override
Public void onPrepared (MediaPlayer mp) {
Mp. SetLooping (true);
Mp. The start ();
}
});
VideoView1. SetOnCompletionListener (new MediaPlayer. OnCompletionListener () {
@ Override
Public void onCompletion MediaPlayer (mp) {
Mp. The reset ();
}
});


RelativeLayout. LayoutParams params2=new RelativeLayout. LayoutParams (RelativeLayout. LayoutParams. WRAP_CONTENT,
RelativeLayout. LayoutParams. WRAP_CONTENT);
Params2. Height=400;
Params2. Width=200;
VideoView videoView2=new VideoView (this);
Uri uri2=Uri. Parse (Environment. External.getexternalstoragedirectory () +
File. The separator + "cef228dfbc0f2b71bb365cf41a1376b7. Mp4");
VideoView2. SetVideoURI (uri2);
VideoView2. SetOnPreparedListener (new MediaPlayer. OnPreparedListener () {
@ Override
Public void onPrepared (MediaPlayer mp) {
Mp. SetLooping (true);
Mp. The start ();
}
});
VideoView2. SetOnCompletionListener (new MediaPlayer. OnCompletionListener () {
@ Override
Public void onCompletion MediaPlayer (mp) {
Mp. The reset ();
}
});
Layout. AddView (videoView1, 0, params1);
Layout. AddView (videoView2, 1, params2);
VideoView2. BringToFront ();
}
Whether first add videoView1 or add videoView2, first add is added after the upper cover
With ImageView to TextView are normal
Ask how to solve

CodePudding user response:

1. To answer your question first: not explicitly specify add control position and dependency,
2. Ask questions: you can add first well in the layout controls, and control the show and hide

CodePudding user response:

reference 1st floor can't write code monkey reply:
1. To answer your question first: not explicitly specify add control position and dependency,
2. Ask questions: you can add first well in the layout controls, and then control the show and hide


1: I this is RelativeLayout, after add should not cover add first, two ImageView or TextView are normal
2: demand is to dynamically add, VideoView, ImageView and TextView, number is
There's a List , the type of View is that 3 kinds, size of the list, only then add VideoView after adding VideoView will appear problem,
After adding VideoView add ImageView, add VideoView is normal
  • Related