Android基于google Zxing实现各类二维码扫描效果

2019-12-10 19:06:54王振洲

我对MipcaActivityCapture界面的布局做了自己的改动,先看下效果图,主要是用到FrameLayout,里面嵌套RelativeLayout。

Android基于google Zxing实现各类二维码扫描效果

布局代码如下

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://www.easck.com/apk/res/android" 
  android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
 
  <RelativeLayout 
    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_gravity="center" /> 
 
    <com.mining.app.zxing.view.ViewfinderView 
      android:id="@+id/viewfinder_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
 
    <include 
      android:id="@+id/include1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      layout="@layout/activity_title" /> 
  </RelativeLayout> 
 
</FrameLayout> 

在里面我将界面上面部分写在另一个布局里面,然后include进来,因为这个activity_title在我项目里面还供其他的Activity使用,我也是直接拷贝出来的

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://www.easck.com/apk/res/android" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:background="@drawable/mmtitle_bg_alpha" > 
 
  <Button 
    android:id="@+id/button_back" 
    android:layout_width="75.0dip" 
    android:text="返回" 
    android:background="@drawable/mm_title_back_btn" 
    android:textColor="@android:color/white" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_marginLeft="2dip" /> 
 
  <TextView 
    android:id="@+id/textview_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/button_back" 
    android:layout_alignBottom="@+id/button_back" 
    android:layout_centerHorizontal="true" 
    android:gravity="center_vertical" 
    android:text="二维码扫描" 
    android:textColor="@android:color/white" 
    android:textSize="18sp" /> 
 
</RelativeLayout>