1. 程式人生 > >Android手勢識別 Camera 預覽介面上顯示文字 佈局注意事項(merge佈局)

Android手勢識別 Camera 預覽介面上顯示文字 佈局注意事項(merge佈局)

通常在Surfaceview作為預覽視訊幀的載體,有時需在上面顯示提示文字。以前我弄的都好好的,今天忽然發現疊加的TextView不管咋弄都出不來文字了,跟Surfaceview一起放在FrameLayout也不行,後來想到merge佈局,發現也不行。大爺的,奇了怪了,最後發現了原因,原來是順序問題。也即無論是在RelativeLayout裡還是merge佈局裡,View是逐個疊加上去的,一層一層鋪上去的。如果你先放TextView在最前面,那肯定被後面的全屏Surfaceview覆蓋了。用常規的RelativeLayout或者merge,只要處理好這個順序問題都可以實現效果。下面附上本文的佈局:

[html] view plaincopyprint?在CODE上檢視程式碼片派生到我的程式碼片
  1. <spanstyle="font-family:Comic Sans MS;font-size:18px;"><mergexmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     tools:context
    =".CameraActivity">
  6.     <FrameLayout
  7.         android:layout_width="wrap_content"
  8.         android:layout_height="wrap_content">
  9.         <SurfaceView
  10.             android:id="@+id/previewSV"
  11.             android:layout_width="0dip"
  12.             android:layout_height="0dip"/>
  13.     </FrameLayout
    >
  14.     <TextView
  15.         android:id="@+id/tv_info"
  16.         android:layout_width="match_parent"
  17.         android:layout_height="wrap_content"
  18.         android:text="開始檢測..."
  19.         android:textColor="@android:color/holo_blue_light"
  20.         android:textSize="25sp"
  21.         android:visibility="visible"/>
  22.     <org.yanzi.ui.HandView
  23.         android:id="@+id/hand_view"
  24.         android:layout_width="match_parent"
  25.         android:layout_height="match_parent"/>
  26.     <ImageButton
  27.         android:id="@+id/photoImgBtn"
  28.         android:layout_width="wrap_content"
  29.         android:layout_height="wrap_content"
  30.         android:layout_gravity="bottom|center_horizontal"
  31.         android:background="@drawable/photo_img_btn"/>
  32. </merge></span>

傳兩張效果圖:

張開手,紅色畫框:


手指合攏,畫藍框: