Android Studio Layout Editor 无法正确渲染 srcCompat 矢量绘图(支持库 23.2)

Android Studio Layout Editor does not render srcCompat vector drawables correctly (support library 23.2)

更新为使用 23.3.1 支持库后,布局编辑器不会使用 app:srcCompat 属性呈现 imageView。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="?android:colorBackground"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="in.srain.demos.vector.MainActivity"
    tools:showIn="@layout/activity_main">

    <ImageView
        android:id="@+id/vector_drawable_cpu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/vector_drawable_cpu"
        />

    <ImageView
        android:id="@+id/vector_drawable_cpu_ani"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@id/vector_drawable_cpu"
        app:srcCompat="@drawable/animated_cpu"
        />

    <TextView
        android:id="@+id/status_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/vector_drawable_cpu"
        android:layout_centerHorizontal="true"
        android:padding="5dp"
        android:textColor="?android:attr/textColorPrimary" />

</RelativeLayout>

Looks like this in the Layout Editor preview

有没有人知道如何解决这个问题?

Android Studio 不支持 app:srcCompat 属性,但您可以添加辅助 tools:src="@drawable/animated_cpu" 属性来提供帮助IDE 在预览和布局编辑器中渲染您的 ImageView。然后你的 ImageView 看起来像这样:

<ImageView
        android:id="@+id/vector_drawable_cpu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/vector_drawable_cpu"
        tools:src="@drawable/animated_cpu"/>