首页 > 解决方案 > 如何在操作栏下保留 VideoView

问题描述

如果在视频上使用 Ontouch,我会制作视频播放器,它会显示动作栏(但在视频上方,就像在 css 中使用 z-index 一样),不会改变视频视图的位置(视频保持在中心位置,但动作栏会占用一些空间视频视图。

这就是我和我得到的(比较):

在此处输入图像描述

文件

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen2);

    mVisible = true;
    mControlsView = findViewById(R.id.fullscreen_content_controls);
    mContentView = findViewById(R.id.fullscreen_content);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mContentView.setOnTouchListener(tester);       
    //findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);

    String path = "android.resource://com.example.asus.exercise/" + R.raw.test;

    Uri u = Uri.parse(path);
    mContentView.setVideoURI(u);
    mContentView.start();
}

xml 文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FullscreenActivity2"
android:elevation="0dp">

<!-- The primary full-screen view. This can be replaced with whatever view
     is needed to present your content, e.g. VideoView, SurfaceView,
     TextureView, etc. -->

<VideoView
    android:id="@+id/fullscreen_content"
    android:layout_width="match_parent"
    android:layout_height="723dp"
    android:fitsSystemWindows="true"
    android:gravity="center"
    android:keepScreenOn="true"
    android:elevation="@dimen/_10sdp"/>

<!-- This FrameLayout insets its children based on system windows using
     android:fitsSystemWindows. -->
<!--<FrameLayout-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="match_parent"-->
    <!--android:fitsSystemWindows="true">-->

    <RelativeLayout
        android:id="@+id/fullscreen_content_controls"
        style="?metaButtonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/black_overlay"
        android:orientation="horizontal"
        tools:ignore="UselessParent"
        android:elevation="0dp">

    </RelativeLayout>

标签: androidandroid-studioandroid-layout

解决方案


在 xml 文件中的组件中尝试使用负值的边距:VideoView

android:layout_marginTop="-10dp"

如果您想以编程方式更改边距,请参考此链接: Android 以编程方式更改边距


推荐阅读