18

我今天开始使用 Android Studio 2.2 和 ConstraintLayout,但在渲染时遇到了一些问题。使用蓝图模式时,一切看起来都很好。使用设计模式时,对象被粘在左上角,全部混合在一起。

Android Studio 警告:onMeasure 错误

java.lang.NoSuchMethodError: android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;Landroid/support/constraint/solver/widgets/ConstraintWidget;Landroid/support/constraint/solver/widgets/ConstraintAnchor$Type;II)V
    at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:517)
    at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:433)
    at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:728)
    at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
    at android.view.View.measure(View.java:19731)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:19731)
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
    at android.view.View.measure(View.java:19731)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:545)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

依赖:

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'

这是 Android Studio 中无法解决的错误还是有什么可以解决的?SDK 已更新。

编辑

XML 文件:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@drawable/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView6"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="16dp" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView33"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/imageView6"
        android:layout_marginLeft="16dp" />

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView34"
        app:layout_constraintRight_toRightOf="@+id/textView33"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/textView33" />
</android.support.constraint.ConstraintLayout>
4

2 回答 2

51

如此处所述 约束布局Alpha8发行说明

注意:由于 API 更改,您可能需要在升级到 alpha 8 后重新启动 Android Studio 2.2 才能使用布局预览。

所以从菜单栏中,选择file并选择invalidate caches / restart

于 2016-09-24T19:18:45.540 回答
0

我更新后遇到了这个问题

implementation 'androidx.constraintlayout:constraintlayout:1.1.3

implementation 'androidx.constraintlayout:constraintlayout:2.0.2'

降级回 1.1.3 解决问题

于 2020-10-21T09:45:47.180 回答