1

After updating to use the 23.3.1 support libraries, the Layout Editor does not render imageViews using the app:srcCompat attribute.

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

Has anyone figured out how to fix this?

p6re9
  • 13
  • 5
  • see my answer [here](http://stackoverflow.com/questions/34417843/how-to-use-vector-drawables-in-android-api-lower-21/36661438#36661438) – mehrdad khosravi May 23 '16 at 09:26

1 Answers1

3

Android Studio doesnt support app:srcCompat attribute, but you can add secondary tools:src="@drawable/animated_cpu" attribute to help IDE render your ImageViews in preview and layout editor. Then your ImageView looks like this:

<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"/>
lukjar
  • 7,220
  • 2
  • 31
  • 40