android - ProgressBar 在 FrameLayout 之上

标签 android android-layout

我有一个奇怪的情况。我正在使用 NexPlayer 在 openGL 模式下渲染流媒体视频。在流式视频(框架布局)的渲染区域之上,只要视频播放器正在缓冲,我就会以不确定模式显示 ProgressBar - 与 youtube 应用程序的功能相当。

在播放器停止缓冲并且我尝试从屏幕上移除进度条之前,这一切都很好。进度条停止动画,但它仍保留在屏幕上,就好像它是视频上的水印一样。 我尝试删除它的方法是更改​​进度条的可见性;我已经尝试过 View.INVISIBLE 和 View.GONE 但都没有用。 我还尝试将进度条包装在另一个布局中并更改该容器的可见性,但无济于事。

我确实注意到,当我旋转设备时,进度条会消失。

下面是播放器 Activity 的 xml 布局。那里的surfaceview仅在设备不支持OpenGL 2.0的情况下使用。

有没有人知道如何摆脱这个 ProgressBar?

提前致谢!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<FrameLayout
    android:id="@+id/gl_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >
</FrameLayout>

<SurfaceView
    android:id="@+id/surface"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true" >
</SurfaceView>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/controlContainer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#aa000000"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <ToggleButton
            android:id="@+id/buttonPausePlay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/selector_play_pause"
            android:textOff=""
            android:textOn="" />

        <ImageButton
            android:id="@+id/buttonStop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#00000000"
            android:src="@drawable/ic_media_stop" />
    </LinearLayout>

    <ProgressBar
        android:id="@+id/seekbar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:indeterminate="false" />
</LinearLayout>

<LinearLayout
    android:id="@+id/loadingContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:gravity="center"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/loading"
        style="@android:style/Widget.ProgressBar.Large.Inverse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true" />

</LinearLayout>

</RelativeLayout>

编辑:更改 View 可见性的代码:

@Override
public void onBuffering(int progress_in_percent) {
    Log.d(TAG, "Buffering " + progress_in_percent + " %");
}

@Override
public void onBufferingBegin() {
    Log.d(TAG, "Buffering begin");
     loadingContainer.setVisibility(View.VISIBLE);
}

@Override
public void onBufferingEnd() {
    Log.d(TAG, "Buffering end");
    loadingContainer.setVisibility(View.GONE);
}

这些方法是从 NexPlayer 框架内调用的。我确信他们确实会被调用,因为我在日志中得到了输出。

最佳答案

是的,我想通了。我从 NexPlayer 框架获得的回调不在 UI 线程上。奇怪的是,这并没有在日志中导致任何堆栈跟踪,所以我没有注意到这一点,直到我附加了我的调试器并添加了一个在任何异常时暂停的断点。

我通过创建与上面的代码执行完全相同的操作并将它们发布到我的处理程序来解决此问题。

(尽管我仍然不明白为什么 ProgressBar 会出现在第一位,因为它也在错误的线程上可见:/)

关于android - ProgressBar 在 FrameLayout 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7916636/

相关文章:

java - 如何为您的 Android 应用程序添加更新通知,然后用户将被引导至 Google Playstore?

android - 更改 Activity 的默认退出动画

java - Android 布局中的绝对居中

android - 我如何制作动态线性布局以在 android 中显示 textview?

java - findViewById() 下仅显示一个 ImageButton

android - 在代码中选择findViewById(R.id.xxx)的资源

java - 仅请求 Android Marshmallow 的运行时权限?

android - 如何在 RxJava 中延迟从列表中发出项目?

适用于 Pre-Lollipop 设备的具有弯曲背景的 Android Ripple 按钮

android - 是否可以包含一个相对于底部而不是顶部元素的按钮?