Android 如何删除矢量资源 Drawable 的内部填充

标签 android xml 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>
我的布局:
<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>
当前输出:
enter image description here
如何删除此矢量可绘制对象的内部填充?任何帮助将不胜感激。

最佳答案

好的,这是我提出的解决方案,不是完美的答案,但可以满足我的需要。
像这样修改 Vector Drawable:

<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>
结果:
enter image description here
enter image description here

该解决方案的好处是,无论您如何更改 ImageView 的大小,目标形状保持其位置(在我的情况下位于底部),因此无需理会RelativeLayout ,只需使用 LinearLayout .
"pivot(12, 12)"解释:https://stackoverflow.com/a/51659233/3466808

关于Android 如何删除矢量资源 Drawable 的内部填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64398830/

相关文章:

android - drawable.setCallback(null) 的后果;

android - 如何将图像从 drawable 传输到 sdcard 中的文件夹?

java - 如何使用 ListViews 创建选项卡式 Activity - Android

python - 控制搜索深度 findall Lxml

android - 在 ImageView 中设置 Vector Drawable 导致应用程序在旧 SDK 中崩溃

android - 错误 : SMS API getting Error in Android App

android - 无法在 VLC android 中流式传输 YouTube 网址

android - 如何引用资源值中的 ?attr/actionBarSize?

Android 在屏幕打开/关闭时显示自己的锁而不是默认锁

php - 按日期排序 XML 数据输出