要实现Android的VideoView的沉浸式重叠控制器,可以按照以下步骤进行:
VideoView videoView = findViewById(R.id.videoView);
RelativeLayout controllerLayout = findViewById(R.id.controllerLayout);
// 设置VideoView沉浸式效果
videoView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == 0) {
controllerLayout.setVisibility(View.VISIBLE);
} else {
controllerLayout.setVisibility(View.GONE);
}
}
});
// 设置控制器视图重叠效果
controllerLayout.bringToFront();
videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
controllerLayout.setVisibility(View.VISIBLE);
}
});
这样,当用户点击视频区域时,控制器视图将会显示出来,当用户不点击时,控制器视图将会自动隐藏。