Android Studio 布局编辑器无法正确呈现 srcCompat 矢量绘图(支持库 23.2)

标签 android android-studio android-support-library

更新为使用 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"/>

关于Android Studio 布局编辑器无法正确呈现 srcCompat 矢量绘图(支持库 23.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35996311/

相关文章:

intellij-idea - IDEA可以自动添加Android支持库吗?

android - Gradle不使用最新版本的支持库吗?

android - 在 Android 中阅读 RSS 时出现 FileNotFoundException

android - 最新的 studio 3.6 中未生成数据绑定(bind)类

android - 更改包名称

Android Studio - Gradle 同步失败 : Already disposed

java - 使用 Scanner 类时未发现行错误

Android sdk 管理器我没有 Android 支持库

android - 使用 Parcelable 将绘图保存到磁盘

android - 如何在 Android 中获取 SharedPreferences 空值