私はチュートリアルに従っており、Android の VideoView を介してカスタム ビデオ プレーヤーを構築しようとしています。
ここで、VideoView に触れると、メディア コントローラーを表示または非表示にします。コントローラーが既に表示されている場合は非表示にし、非表示の場合は表示します。
これらのメディア コントローラーは、VideoView の上にある 2 つの LinearLayouts によって表されます。赤で強調表示された領域は、背景の VideoView 境界を表します。
私の問題は、VideoView と重なっているメディア コントローラーの領域に触れると、メディア コントローラーが非表示になることです。VideoView ではなく LinearLayout に直接触れているため、これは望ましい効果ではありません。
では、LinearLayouts をクリックしているときに Videoview がタッチ イベントをキャッチするのはなぜですか?
これが私のonTouch
実装です:
@Override
public boolean onTouch(View v, MotionEvent event) {
if (!isMediaControlerShown) {
topPanel.setVisibility(View.VISIBLE);
bottomPanel.setVisibility(View.VISIBLE);
isMediaControlerShown = true;
} else {
topPanel.setVisibility(View.GONE);
bottomPanel.setVisibility(View.GONE);
isMediaControlerShown = false;
}
return false;
}
XML レイアウトのスキームは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content" />
<!-- The top panel of the Video Player -->
<LinearLayout
android:visibility="gone"
android:id="@+id/top_panel"
style="@style/VideoTopPanel"
android:orientation="vertical" >
<!-- ////// -->
</LinearLayout>
<!-- The bottom panel of the Video Player -->
<LinearLayout
android:visibility="gone"
android:id="@+id/bottom_panel"
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/VideoBottomPanel"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:paddingBottom="@dimen/video_bottom_panel_padding_bottom"
android:paddingTop="@dimen/video_bottom_panel_padding_top" >
<!-- ////// -->
</LinearLayout>
</RelativeLayout>