2011-05-30 48 views

回答

13

一個很好的例子可以在ZXing庫,Barcode Scanner應用程序中找到。

他們做什麼是他們使用FrameLayoutSurfaceView和他們的自定義ViewfinderView這樣既SurfaceViewViewfinderView被覆蓋全屏幕:

<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> 

注意fill_parentlayout_heightlayout_width兩種意見。

然後他們在ViewfinderView.onDraw()方法中繪製自定義事件,只是在攝像頭預覽顯示內容的頂部。

如果你不想畫任何東西,但只是使用預定義的圖像,然後使用ImageView而不是ViewfinderView。您可能會考慮調用setAlpha方法來使圖像透明(如果drawable本身不是透明的)。


這裏是從條碼掃描儀的屏幕截圖:

enter image description here