'Android: How to disable scanning in transparent area
I'm using google.zxing.code library for scanning QR codes. I'm having PreviewView in full screen and I'm trying to make it working in only center part and other part should be transparent as attached screenshot. But its scanning successfully in top and bottom transparent area.
I need this are just transparent and scanner should not load result if QR code comes in this area. I'm using below snippet for this.
<androidx.camera.view.PreviewView
android:id="@+id/preview_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#CC000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#CC000000" />
<LinearLayout
android:id="@+id/camera_view"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#CC000000" />
<RelativeLayout
android:id="@+id/rlscan"
android:layout_width="280dp"
android:layout_height="fill_parent">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#CC000000" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#CC000000">
<TextView
android:id="@+id/txtResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:text="Please focus Camera to QR Code"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
Please help me if someone knows the approach. Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

