RelativeLayout添加2个VideoView层级错误
雕·不懒惰 2021-01-13 11:27:22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</RelativeLayout>
private RelativeLayout layout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.empty);
layout = findViewById(R.id.layMain);
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.setMargins(0, 100, 0, 0);
VideoView videoView1 = new VideoView(this);
Uri uri1 = Uri.parse(Environment.getExternalStorageDirectory() + File.separator +
"ca0b8818341dd777b953017d731a22d1.mp4");
videoView1.setVideoURI(uri1);
videoView1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
}
});
videoView1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.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.getExternalStorageDirectory() +
File.separator+"cef228dfbc0f2b71bb365cf41a1376b7.mp4");
videoView2.setVideoURI(uri2);
videoView2.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
}
});
videoView2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.reset();
}
});
layout.addView(videoView1, 0, params1);
layout.addView(videoView2, 1, params2);
videoView2.bringToFront();
}
不管是先add videoView1 还是先add videoView2,先添加的都是在上层覆盖了后添加的
换成ImageView,TextView都是正常的
求怎么解决