2

I have a GLSurfaceView that I want to put inside a ScrollView. I accomplished this by adding a FrameLayout inside a LinearLayout which was added to the ScrollView.

Everyhing works nice, except that I am getting a black border on top of the GLSurfaceView when scrolling. When the screen is still, everyhing looks nice. Anybody have any ideas.

<?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"/>

enter image description here

genpfault
  • 51,148
  • 11
  • 85
  • 139
Martin Tramšak
  • 607
  • 1
  • 7
  • 12

1 Answers1

6

Generally speaking, you don't want to move SurfaceView (or its subclasses) around the screen. Bear in mind that SurfaceView has two parts, the Surface and the View. The View part -- usually just a transparent "hole" used during layout -- is handled by the app. The Surface part is a separate graphics layer composited by the system, and its size and position are managed by the Window Manager.

When you move a SurfaceView, the View part moves immediately, but the Surface lags behind, because moving it requires communicating with other processes. You should expect to see a black bar in the direction that the View is moving, because you've temporarily exposed an area outside what the Surface covers.

The preferred way to handle this is to use a TextureView, which behaves just like other Views. You would need to do your own EGL setup and thread management, since GLSurfaceView won't be handling those for you. You can find some examples in Grafika.

fadden
  • 51,356
  • 5
  • 116
  • 166