android - 如何在操作栏下保留 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>
解决方案
在 xml 文件中的组件中尝试使用负值的边距:VideoView
android:layout_marginTop="-10dp"
如果您想以编程方式更改边距,请参考此链接: Android 以编程方式更改边距
推荐阅读
- sql - 提取列中的特定单词
- python - 具有多个输入属性的 LSTM,在 keras
- python-3.x - 获取按其他列值过滤的 datetimeindexed 数据帧中当天的最后一个值
- c# - 在不同的类中实现接口签名如何知道使用哪一个
- python - Binaryproto 平均大小不同于 cnn 大小
- ios - 如果我不通过 App Store 分发我的应用程序,我如何注册应用程序方案以获得深度链接?
- android - Picasso - 回调,指示从 Web 加载的位图
- php - 错误:非对象的属性
- angular - 从 url 检索正确日期的问题
- java - HttpURLConnection 错误:HTTP 方法 PATCH 无效