Android ScrollView 中的 GLSurfaceView 产生黑边

Android GLSurfaceView in ScrollView produces black borders

我有一个要放在 ScrollView 中的 GLSurfaceView。我通过在添加到 ScrollView 的 LinearLayout 中添加一个 FrameLayout 来完成此操作。

除了滚动时我在 GLSurfaceView 顶部出现黑色边框外,一切都很好。当屏幕静止时,一切看起来都很好。任何人有任何想法。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="900dp"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="35dp"
            android:visibility="visible"
            android:weightSum="1"
            android:overScrollMode="never">

            <FrameLayout
                android:id="@+id/ecg_graph"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

一般来说,您不想在屏幕上移动 SurfaceView(或其子类)。请记住,SurfaceView 有两个部分,Surface 和 View。视图部分——通常只是在布局期间使用的透明 "hole"——由应用程序处理。 Surface部分是系统合成的独立图形层,其大小和位置由WindowManager管理。

当你移动一个SurfaceView时,View部分立即移动,但是Surface滞后,因为移动它需要和其他进程通信。您应该会在 View 移动的方向看到一个黑条,因为您暂时暴露了 Surface 覆盖范围之外的区域。

处理此问题的首选方法是使用 TextureView,它的行为与其他视图一样。您需要自己进行 EGL 设置和线程管理,因为 GLSurfaceView 不会为您处理这些。您可以在 Grafika.

中找到一些示例