Android 如何删除矢量资源可绘制的内部填充

Sam*_*hen 6 xml android drawable android-drawable android-vectordrawable

我从 Vector Asset 中绘制的矢量:

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:tint="@android:color/holo_purple"
    android:viewportWidth="24"
    android:viewportHeight="24">

    <path
        android:fillColor="@android:color/white"
        android:pathData="M7,14l5,-5 5,5z" />

</vector>
Run Code Online (Sandbox Code Playgroud)

我的布局:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/ic_baseline_arrow_drop_up_24" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/background"
        android:text="Hi, my name is Sam"
        android:textColor="@android:color/white"
        android:textSize="30sp" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

电流输出:

在此输入图像描述

如何删除这个矢量可绘制的内部填充?任何帮助将不胜感激。

Sam*_*hen 4

好吧,这是我想出的解决方案,不是完美的答案,但满足了我的需求。

像这样修改矢量绘图:

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:tint="@android:color/holo_purple"
    android:viewportWidth="24"
    android:viewportHeight="24">

    <group                       //key point
        android:pivotX="12"      //(12, 12) is the center accordig to the viewport, see link below
        android:pivotY="12"
        android:scaleX="2.0"     //twice bigger, adjust as needed
        android:scaleY="2.0"
        android:translateY="8">  //move downward, asjust as needed

        <path
            android:fillColor="@android:color/white"
            android:pathData="M7,14l5,-5 5,5z" />

    </group>

</vector>
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

在此输入图像描述


此解决方案的好处是,无论您如何更改 的大小ImageView,目标形状仍保持其位置(在我的例子中位于底部),因此无需费心RelativeLayout,只需使用LinearLayout

“pivot(12, 12)”解释: https: //stackoverflow.com/a/51659233/3466808