首页 > 解决方案 > 为什么android在多次构建后显示错误的向量

问题描述

我已经在不同的应用程序中遇到这个问题很长时间了。我有分配给我的矢量绘图ImageView。起初安装一切正常,每个 ImageView 都显示正确的可绘制对象,但在数十次构建和运行后,应用程序开始放错可绘制对象并将它们显示在错误的图像视图中,解决方案是完全卸载应用程序然后安装它。这在构建阶段有效,但我总是问我的问题,当用户收到十几个更新时会发生什么,这不会发生在他们身上吗?我没有使用pngs,但因此这与andvectors无关。multiple res foldersscreen sizes

所以这是我的应用程序经过十几个构建

在此处输入图像描述

这是在全新安装之后

在此处输入图像描述

当您在无法丢失的应用程序上处理数据时,这真的很令人沮丧,我不得不丢失我保存的地址只是为了让图标正确显示。有没有人遇到过这个问题,他们是如何解决的?

标签: androidimageviewandroid-vectordrawable

解决方案


由于我有一个选择的数量,drawables我最终只是在我的布局中添加了一个检查,比如

<data>
    <import type="my.app.R"/>
</data>

<androidx.appcompat.widget.AppCompatImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:background="@drawable/round_color_primary"
        android:padding="@dimen/small_margin"
        app:imageResource="@{address.type.value == 120 ? R.drawable.ic_home : (address.type.value == 121 ? R.drawable.ic_work : (address.type.value == 124 ? R.drawable.ic_star : R.drawable.ic_destination_outline))}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:tint="@color/white" />

推荐阅读