ina*_*ruk 13
在ZXing库,Barcode Scanner应用程序中可以找到一个很好的例子.
他们所做的事情是,他们使用FrameLayout了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>
Run Code Online (Sandbox Code Playgroud)
请注意两个视图中的fill_parent值layout_height和layout_width两个视图的值.
然后他们在ViewfinderView.onDraw()方法中绘制自定义内容,只是在相机预览显示的内容之上.
如果您不想绘制任何内容,只是使用预定义图像,则使用ImageView而不是ViewfinderView.您可以考虑调用setAlpha方法使图像透明(如果drawable本身不是透明的).
以下是Barcode Scanner的截图:

| 归档时间: |
|
| 查看次数: |
7714 次 |
| 最近记录: |