Home > Mobile >  RelativeLayout dynamically add VideoView hierarchy problem
RelativeLayout dynamically add VideoView hierarchy problem

Time:09-15

Public class ViewActivity extends AppCompatActivity {
Private RelativeLayout. LayoutParams r_params;
Private RelativeLayout RelativeLayout.
Private RelativeLayout layMain;


@ Override
Protected void onCreate (@ Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Viewtest);
LayMain=the findViewById (R.i d.l aymain);//empty layout

AddMedia (0, new VideoView (this));

The new Handler (.) postDelayed (new Runnable () {
@ Override
Public void the run () {
Handler. RemoveCallbacks (this);
AddMedia (1, new VideoView (ViewActivity. This));
}
}, 5000);
}
Private void addMedia (int index, final VideoView VideoView) {
RelativeLayout. LayoutParams params=new RelativeLayout. LayoutParams (RelativeLayout. LayoutParams. WRAP_CONTENT,
RelativeLayout. LayoutParams. WRAP_CONTENT);
Params. Width=(index==0? 1080:640);
Params. Height=(index==0? 1920:360);
Params. TopMargin=(index==0? 200:100);
Params. LeftMargin=(index==0? 0-200);
VideoView. SetLayoutParams (params);

Uri Uri=Uri. Parse (Environment. External.getexternalstoragedirectory () + "/09 bc7cac2a9d8203bdf9538bf22f93bc. Mp4");
VideoView. SetVideoURI (uri);

VideoView. SetOnPreparedListener (new MediaPlayer. OnPreparedListener () {
@ Override
Public void onPrepared (MediaPlayer mp) {
Mp. The start ();
Mp. SetLooping (true);
}
});
VideoView. SetOnErrorListener (new MediaPlayer. one rrorListener () {
@ Override
Public Boolean one rror (MediaPlayer mp, int what, int extra) {
VideoView. StopPlayback ();
Return true;
}
});
VideoView. SetOnCompletionListener (new MediaPlayer. OnCompletionListener () {
@ Override
Public void onCompletion MediaPlayer (mp) {
Mp. The reset ();
Mp. Release ();
}
});

LayMain. AddView (videoView, index);

LayMain. BringChildToFront (videoView);
LayMain. UpdateViewLayout (videoView params);
}

After adding the videoView is covered, not cover added videoView first

CodePudding user response:

My experiment, to successively adding two ImageView is normal
With mixed with the ImageView VideoView add, whichever first add is normal
Anyway, mix to add, change index is normal, why can't the rest of 2 VideoView, into two SurfaceView is also not line
  • Related