简体   繁体   English

Android VideoView隐藏布局元素

[英]Android VideoView hides Layout Elements

I have the following layout (cut down to a minimal example) 我有以下布局(简化为最小示例)

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

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/free_text_default_bg"
        android:gravity="center_horizontal"
        android:padding="@dimen/free_text_padding"
        android:text="background element is a video view" />

</RelativeLayout>

The problem is, that if I move the EditText around (it has a drag listener attached to it), it dissapears at a certain point of the screen as you can see in this screenshot. 问题是,如果我四处移动EditText(附加了一个拖动侦听器),它将在屏幕的某个点消失,如您在此屏幕快照中所见。

在此处输入图片说明

The problem seems to only appear when I have a VideoView. 该问题似乎仅在有VideoView时出现。 Even if I don't show a video. 即使我不显示视频。 When I replace it with eg an ImageView there is no problem at all. 当我将其替换为例如ImageView时,完全没有问题。

So my question is, what's happening and how can I resolve this? 所以我的问题是,发生了什么事,我该如何解决?

Thanks for your time! 谢谢你的时间!

UPDATE 1: This only happens if the VideoView has 更新1:仅当VideoView具有

android:layout_height="match_parent"

when I set it to some "dp" value everything works just fine... 当我将其设置为某些“ dp”值时,一切正常。

I did not find a solution to my question jet but I have found a workaround: Once the layout is finished, I get the height from the parent container, subtract 1px and set this as new height for the video view. 我没有找到问题解决方案,但找到了一种解决方法:布局完成后,我从父容器中获取高度,减去1px并将其设置为视频视图的新高度。 The 1px is barely visible... 1px几乎看不见...

Here is the code: 这是代码:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    ViewGroup.LayoutParams layoutParams = videoView.getLayoutParams();
    layoutParams.height = parentView.getHeight() - 1;
    videoView.setLayoutParams(layoutParams);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM