如何在exoplayer的自定义UI布局中找到自定义按钮?

我想使用这些代码来自定义exoplayer的用户界面

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/exoplayer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:controller_layout_id="@layout/control_view_normal"/>

这是control_view_normal,对应于app:controller_layout_id

然后我尝试在代码中找到 exo_fullscreen_button

 View controlView = videoView.findViewById(R.id.exo_controller);
 controlView.findViewById(R.id.exo_fullscreen_button)  
            .setOnClicklistener(v -> {           //null pointer exception! why?
                    ((activity)context).setRequestedOrientation(activityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                });

此外,编译器给我一个controlView.findViewById(R.id.exo_fullscreen_button)为空指针。 有人知道如何在自定义布局中找到自定义按钮吗?

xzgfzcnk 回答:如何在exoplayer的自定义UI布局中找到自定义按钮?

您还需要定义exo_controller_placeholder,这应该是将被您的自定义控制器替换的任何虚拟视图

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/exoplayer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:controller_layout_id="@layout/control_view_normal"
    app:exo_controller_placeholder="@+id/view_holder"/>
<View 
    android:id="@+id/view_holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</FrameLayout>
本文链接:https://www.f2er.com/3075715.html

大家都在问