Android ROI background

Asked by At

I am trying to create a view with background and a ROI like in this image:

enter image description here

How can I create such background in Android? I've succeed to create the square with black opacity and yellow stroke as following:

   <View
        android:background="@color/black_with_80_alpha"
        android:layout_width="0dp"
        android:layout_height="0dp"
        custom:layout_constraintTop_toTopOf="@+id/roi"
        custom:layout_constraintBottom_toBottomOf="@id/roi"
        custom:layout_constraintRight_toRightOf="parent"
        custom:layout_constraintLeft_toRightOf="@+id/roi"/>

<View
        android:background="@color/black_with_80_alpha"
        android:layout_width="0dp"
        android:layout_height="0dp"
        custom:layout_constraintTop_toTopOf="@+id/roi"
        custom:layout_constraintBottom_toBottomOf="@id/roi"
        custom:layout_constraintRight_toLeftOf="@id/roi"
        custom:layout_constraintLeft_toLeftOf="parent"/>

<View
        android:background="@color/black_with_80_alpha"
        android:layout_width="0dp"
        android:layout_height="0dp"
        custom:layout_constraintTop_toBottomOf="@+id/toolbar"
        custom:layout_constraintBottom_toTopOf="@id/roi"
        custom:layout_constraintRight_toRightOf="parent"
        custom:layout_constraintLeft_toLeftOf="parent"/>

<View
        android:background="@color/black_with_80_alpha"
        android:layout_width="0dp"
        android:layout_height="0dp"
        custom:layout_constraintTop_toBottomOf="@+id/roi"
        custom:layout_constraintBottom_toBottomOf="parent"
        custom:layout_constraintRight_toRightOf="parent"
        custom:layout_constraintLeft_toLeftOf="parent"/>
<View
        android:id="@+id/roi"
        android:layout_width="0dp"
        android:layout_height="0dp"
        custom:layout_constraintDimensionRatio="1:1"
        android:layout_margin="50dp"
        android:background="@drawable/qr_roi_bg"
        custom:layout_constraintStart_toStartOf="parent"
        custom:layout_constraintEnd_toEndOf="parent"
        custom:layout_constraintTop_toTopOf="parent"
        custom:layout_constraintBottom_toBottomOf="parent"
        />

This is the yellow stroke bg:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/transparent" />
    <stroke android:color="@color/greenish_yellow" android:width="1dp"/>
</shape>

This draws nice accurate square with even yellow stroke. The question is how can I create these yellow corners.

0 Answers