0

I am trying to embed a customized SurfaceView inside a HorizontalScrollView. I have set up everything correctly but I don't get a callback to my surfaceCreated() which is implemented as a part of SurfaceHolder.Callback interface. The part of the layout xml is:

..........
    <HorizontalScrollView
        android:id="@+id/horizScroller"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none">

            <com.purandara.views.PitchSurfaceView
                android:id="@+id/pitchView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginTop="@dimen/lesson_page_title_bar_height"
                android:layout_marginBottom="@dimen/lesson_page_ctrl_bar_height"/>

    </HorizontalScrollView>
..............

I came across this blog article which sayas that it is difficult to use a SurfaceView inside a ListView or a ScrollView. But, does it mean that I cannot even create a customized SurfaceView inside a HorizontalScrollView? What I understand from this is that, since a SurfaceView does not live in the application window, it cannot be mentioned in the xml which is the layout for the entire activity and has other components as well. Rather, we can inflate a layout containing only a SurfaceView and then attach it to the layout of our activity.

As mentioned in the blog article, I tried using TextureView and I am successfully getting a callback to the onSurfaceTextureAvailable() method implemented as a part of TextureView.SurfaceTextureListener interface.

Please let me know if there is some error in my understanding.

Edit 1:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_evaluation);
....................

In my onCreate() method, I have set the content view as mentioned above where the the activity_evaluation is a FrameLayoutcontaining the HorizontalScrollView as an immediate child.

In the constructor of my custom view, I get the handle of the SurfaceHolder and then setting the listener for the SurfaceHolder.CallBack by

mSurfaceHolder = getHolder();
mSurfaceHolder.addCallback(this);

which I guess is a very standard way of doing this. After doing this, when I load my activity, I see a black colored blank screen where my customized SurfaceView is supposed to show and I do not get a callback on my surfaceCreated() method. Let me know if you need more information on this. Thanks.

Swapnil
  • 1,870
  • 2
  • 23
  • 48
  • SurfaceView doesn't scroll well because the View part and the Surface part are independent. When the View moves, it has to send an IPC request to the window manager to move the Surface, which means the movement lags behind by a couple of frames. Since you have TextureView working, you should probably stick with that. Not sure why the callback isn't firing; you'd need to show some code (e.g. onCreate()) if you want to get to the bottom of it. – fadden Dec 22 '15 at 16:40
  • I have added some code and explanation for my implementation. – Swapnil Dec 22 '15 at 17:12

0 Answers0