I know a lot of people have had similar issues to this but I cannot find a solution. I have created a custom View which extends SurfaceView. This view works perfectly when I use :
setContentView(graphView);
However I want it to be embedded inside a HorizontalScrollView. If I try this with xml with:
<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>
Then I get a fatal exception and my application closes.
If I try to solve this programatically with:
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);
Then the screen is just black. I've also tried many variatio开发者_Go百科ns on the code shown above but none have been successful. Where am I going wrong?
You should be able to get it in xml no problem - try embedding your custom graph view inside a ListView inside the scroll view; in my experience with horizontalScrollView they tend to be very pick about their contents. If that doesn't work, try testing to see if there is a problem with the frame view. Just add a button to the horizontal scroll view and see if you can get that to show up. If not, then there is a problem trying to display the frame, and it has nothing to do with your custom code.
Turns out this isn't really the way to solve this issue:
http://www.mail-archive.com/android-developers@googlegroups.com/msg45804.html
My solution is that I'm not going to use SurfaceView, instead I'm probably going to draw to a Bitmap and put that in an imageview which I can then put inside a ScrollView.
精彩评论