Android ROI背景

时间:2019-04-29 12:01:54

标签: android android-layout android-shape

我正在尝试创建一个具有背景和ROI的视图,如下图所示:

enter image description here

如何在Android中创建这样的背景? 我成功创建了具有黑色不透明和黄色笔触的正方形,如下所示:

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

这是黄色描边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>

这将绘制出非常精确的正方形,甚至带有黄色笔触。 问题是如何创建这些黄色角。

0 个答案:

没有答案