我正在尝试在SurfaceView
内嵌入自定义的HorizontalScrollView
。我已经正确设置了所有内容,但是我没有得到surfaceCreated()
的回调,这是作为SurfaceHolder.Callback
接口的一部分实现的。布局xml的一部分是:
..........
<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>
..............
我遇到过这篇blog文章,说明在ListView或ScrollView 中使用SurfaceView很难。但是,这是否意味着我甚至无法在SurfaceView
内创建自定义HorizontalScrollView
?我从中理解的是,由于SurfaceView
不存在于应用程序窗口中,因此在xml中无法提及它是整个活动的布局,并且其他组件也是如此好。相反,我们可以扩展仅包含SurfaceView
的布局,然后将其附加到我们活动的布局中。
正如博客文章中所提到的,我尝试使用TextureView
,并且我成功获得了作为onSurfaceTextureAvailable()
接口一部分实现的TextureView.SurfaceTextureListener
方法的回调。
如果我的理解有误,请告诉我。
编辑1:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_evaluation);
....................
在我的onCreate()方法中,我设置了上面提到的内容视图,其中activity_evaluation
是FrameLayout
,其中包含HorizontalScrollView
作为直接子项。
在我的自定义视图的构造函数中,我获取SurfaceHolder
的句柄,然后通过
mSurfaceHolder = getHolder();
mSurfaceHolder.addCallback(this);
我猜这是一种非常标准的做法。执行此操作后,当我加载活动时,我会看到一个黑色的空白屏幕,我的自定义SurfaceView
应该显示在我的surfaceCreated()
方法上。如果您需要更多相关信息,请与我们联系。
感谢。