【问题标题】:Android Studio Layout Editor does not render srcCompat vector drawables correctly (support library 23.2)Android Studio 布局编辑器无法正确渲染 srcCompat 矢量可绘制对象(支持库 23.2)
【发布时间】:2016-03-14 19:26:49
【问题描述】:

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

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

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

【问题讨论】:

  • 看我的回答here

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


【解决方案1】:

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"/>

【讨论】:

猜你喜欢
  • 2016-06-15
  • 1970-01-01
  • 2016-11-04
  • 2021-03-24
  • 1970-01-01
  • 2017-10-12
  • 1970-01-01
  • 2020-10-16
  • 1970-01-01
相关资源
最近更新 更多