在图像顶部的android中绘制一个功能区

问题描述 投票:0回答:1

我有一个背景作为图像的ImageView。我想在图像上绘制一条色带来描述它。我尝试了以下代码,但三角形的形状是黑色。因此它无法应用于具有背景图像的视图。

<item>
    <shape android:shape="rectangle">
        <size
                android:width="100dp"
                android:height="40dp"/>
        <solid android:color="@android:color/holo_orange_dark"/>
        <corners android:radius="6dp"/>
    </shape>
</item>


<item
        android:top="-26dp"
        android:bottom="31dp"
        android:left="-90dp"
        android:right="75dp">
    <rotate
            android:fromDegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/black"/>
        </shape>
    </rotate>
</item>

将三角形颜色设置为透明也不起作用。我想像这样掩盖矩形中的三角形:

Banner sample

java android drawable
1个回答
0
投票

根据我的建议,你可以使用矢量像这样的丝带,并检查这个link for imageview on imageview

  <?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
    android:fillColor="#76c304"
    android:strokeWidth="1"
    android:pathData="M9.85 12L3.3 18.55L24 18.55L24 6.63L3.3 6.63L9.85 12Z" /></vector>

要么

 <?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
    android:fillColor="#7c2a58"
    android:strokeWidth="1"
    android:pathData="M6.75 5.56L3.98 8.33L23.76 8.33L23.76 2.67L3.98 2.67L6.75 5.56Z" />
<path
    android:fillColor="#7c2a58"
    android:strokeWidth="1"
    android:pathData="M6.75 12.24L3.98 15.01L23.76 15.01L23.76 9.35L3.98 9.35L6.75 12.24Z" />
<path
    android:fillColor="#7c2a58"
    android:strokeWidth="1"
    android:pathData="M6.75 18.56L3.98 21.33L23.76 21.33L23.76 15.67L3.98 15.67L6.75 18.56Z" /></vector>
© www.soinside.com 2019 - 2024. All rights reserved.