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

时间:2016-03-14 19:26:50

标签: android android-studio android-support-library

更新后使用23.3.1支持库时,布局编辑器不会使用app:srcCompat属性渲染imageViews。

<?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

有没有人想出如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

Android Studio不支持app:srcCompat属性,但您可以添加辅助工具:src =&#34; @ drawable / animated_cpu&#34; 属性,以帮助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"/>