我创建了一个自定义视图,如下所示。我在其他xml文件中声明了这个自定义视图。我遇到的问题是当我打电话时
MyVideoView.setVisibility(View.GONE)
之前在SurfaceView上绘制的视频仍然可见。不应该设置整个View的可见性影响孩子吗?我错过了什么吗?
public class MyVideoView extends FrameLayout {
private SurfaceView videoSurfaceView;
private SurfaceView subtitleSurfaceView;
public MyVideoView(Context context) {
super(context);
initView(context);
}
private void initView(Context context) {
View.inflate(context, R.layout.widget_my_video_view, this);
videoSurfaceView = (SurfaceView) findViewById(R.id.svPlaybackSurface);
subtitleSurfaceView = (SurfaceView) findViewById(R.id.svSubtitles);
}
}
widget_my_video_view.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/svPlaybackSurface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
<SurfaceView
android:id="@+id/svSubtitles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginStart="@dimen/paddingRegular"
android:layout_marginEnd="@dimen/paddingRegular"
android:layout_marginBottom="@dimen/paddingLarge"
android:visibility="invisible"/>
</FrameLayout>