How to wrap the content of a SurfaceView?
I have surfaceView class that is modeled after this, I populated it with 6 bitmaps. Is there a way to wrap the surfaceView around the bitmaps, instead of it covering the entire screen.
I have try this in my xml file:
<LinearLayout
xmlns:开发者_如何学运维android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<com.android.customclasses.Panel
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</com.android.customclasses.Panel>
</LinearLayout>
but this does not work. it just fill the parent.
Thanks.
I don't think that SurfaceView has a notion of "wrap_content" (other than perhaps interpreting it to mean "fill_parent"). You would have to override onMeasure
in your custom class Panel
and call setMeasuredDimension
with the appropriate size.
If you think about this it makes sense: your bitmaps are not inside the SurfaceView
in the view hierarchy. They are simply being drawn by graphics commands to a SurfaceView
which has a predetermined size.
精彩评论