渲染问题 渲染期间引发异常:颜色和位置数组必须具有相同的长度。

11

你好,我在Android Studio中遇到了渲染错误。有人知道这是为什么吗?

我的xml:

    <!-- ListRow Left side Thumbnail image -->

    <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="5dip"
        android:background="@drawable/image_bg"
        android:padding="0dip" >

    <ImageView
         android:id="@+id/list_image"
         android:layout_width="50dip"
         android:layout_height="50dip"
         android:scaleType="centerCrop"
          />
    </LinearLayout>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_marginTop="0dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="De Titel van het geweldige bericht"
        android:textColor="#60a926"
        android:textSize="15dip"
        android:textStyle="bold"
        android:ellipsize="end"
        android:typeface="sans" />

    <TextView
        android:id="@+id/subtitle"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_below="@id/title"
        android:layout_marginTop="0dip"
        android:layout_toLeftOf="@+id/imageView1"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Nieuwsbericht subtitel mooi iets ..."
        android:textStyle="bold"
        android:ellipsize="end"
        android:textColor="#9f9e9f"
        android:textSize="10dip" />


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/arrow" />

    <!-- datum van bericht -->
    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/artist"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginTop="18dp"
        android:layout_marginLeft="175dp"
        android:gravity="right"
        android:text=""
        android:textColor="#ffffff"
        android:textSize="10dip"
        android:textStyle="bold" />

</RelativeLayout>

当我使用预览功能时,出现了这个错误:

"Rendering Problems Exception raised during rendering: color and position arrays must be of equal length"

这是一个 Android Studio 的 bug 还是我做错了什么?

希望有人能提供解决方案。

5个回答

15

首先禁用自动选择最佳功能(您可以在下面的图像上看到)。

然后选择非预览 API 版本进行呈现。

就是这样,对我有用 :)

enter image description here

此答案也适用于修复使用未更新的构建工具版本呈现时出现的问题。另一种解决方法:

打开 SDK 管理器 并将 Build Tools 版本更新为 预览渠道,以便在呈现时使用 Preview 版本的 Build Tools


10

渐变图形中使用的颜色必须是相同类型

这意味着在xml的渐变中,颜色应声明为十六进制格式或attr?color格式。混合使用会导致此错误。

例如:

以下代码将导致崩溃:

 <gradient
        android:angle="90"
        android:centerColor="@color/semi_transparent_white"
        android:endColor="@color/semi_transparent_white"
        android:startColor="?attr/colorAccent" <!--Error: Cant mix color and attr -->
        android:type="linear" />

这不会起作用。

 <gradient
        android:angle="90"
        android:centerColor="@color/semi_transparent_white"
        android:endColor="@color/semi_transparent_white"
        android:startColor="@color/colorThemeAccent"
        android:type="linear" />

谢谢您的回答。这个问题似乎在较新版本的Android(约2023年)中已经得到解决。我很想知道过去是什么原因导致了这个问题。 - JohnnyLambada

2
今天是2015年4月14日(15Apr14)。 “Rendering problems exception raised during rendering”(在渲染过程中出现了渲染问题异常)。
以下是我成功解决问题的方法。
我的Android SDK管理器已下载19、19.1、22和24.1.2版本。22.0.0版本未列在我的SDK管理器中。我双击了Android Studio下的Gradle Scripts中的“build.gradle (Module App)”并更改了该行:
compile 'com.android.support:appcompat-v7:22.0.0'为 compile 'com.android.support:appcompat-v7:19.1'
然后,在渲染器上方的下拉菜单中,旁边有一个小Android图标(称为“要使用的Android版本…”下拉菜单),我选择了“API 19:Android 4.4.2”。
渲染成功。
之前,在同一脚本中,目标版本和构建工具版本都设置为19:
buildToolsVersion "19.1.0" targetSdkVersion 19

2

我解决了这个问题。问题是由于使用了一个错误的渐变样式文件导致的。删除渐变文件后,问题得到了解决。


2

我通过在Android预览版本(例如Android N)上禁用预览功能来解决了此问题。

这也有助于解决其他相关问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接