我知道很多人都有过类似的问题,这一点,但我不能找到一个解决我的自定义视图是不可见的。我创建了一个扩展SurfaceView的自定义视图。当我使用这个视图完美的作品:嵌入里面的时候HorizontalScrollView
setContentView(graphView);
但是我希望它被嵌入在HorizontalScrollView内。如果我用xml试试这个:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<com.stuff.graph.GraphView
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</HorizontalScrollView>
</FrameLayout>
然后我得到一个致命的异常,我的应用程序关闭。
如果我尝试使用编程解决这个问题:
graphView = new GraphView(this);
graphView.setVisibility(View.VISIBLE);
myScrollView = new HorizontalScrollView(this);
graphView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myScrollView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myScrollView.addView(graphView);
setContentView(myScrollView);
这时屏幕只是黑色的。我也在上面显示的代码上尝试了很多变体,但都没有成功。我哪里错了?
你的GraphView扩展了什么.. – ngesh
它扩展了SurfaceView,实现了SurfaceHolder.Callback – user650309