问题描述
|
我想在Camera SurfaceView \\ preview顶部看到图像。
我怎么做?有什么例子吗?
解决方法
在ZXing库的Barcode Scanner应用程序中可以找到一个很好的例子。
他们所做的是将ѭ0用作
SurfaceView
,并将其自定义ViewfinderView
用作SurfaceView
和ViewfinderView
覆盖全屏:
<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\">
<SurfaceView android:id=\"@+id/preview_view\"
android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\"
android:layout_centerInParent=\"true\"/>
<com.google.zxing.client.android.ViewfinderView
android:id=\"@+id/viewfinder_view\"
android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\"
android:background=\"@color/transparent\"/>
</FrameLayout>
注意两个视图的views7ѭ和layout_width
中的fill_parent
值。
然后,它们以ViewfinderView.onDraw()
方法绘制自定义内容,位于相机预览显示的内容之上。
如果您不想绘制任何东西,而只是使用预定义的图像,则使用ImageView
代替ViewfinderView
。您可以考虑调用setAlpha
方法来使图像透明(如果drawable本身还不透明)。
这是条形码扫描仪的屏幕截图: