android – 约束 – 布局lib更新从1.0.2到1.1.0出错(Guideline.getAnchor)

前端之家收集整理的这篇文章主要介绍了android – 约束 – 布局lib更新从1.0.2到1.1.0出错(Guideline.getAnchor)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前使用以下lib的约束布局

实现’com.android.support.constraint:constraint-layout:1.0.2′

通过android studio中的更新警告,我将此更新为

实现’com.android.support.constraint:constraint-layout:1.1.0′

之后,每当我尝试构建或运行项目时,我都会遇到以下问题(请参阅堆栈跟踪)

java.lang.AssertionError: TOP
    at android.support.constraint.solver.widgets.Guideline.getAnchor(Guideline.java:159)
    at android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(ConstraintWidget.java:1579)
    at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1012)
    at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:793)
    at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1540)
    at android.view.View.measure(View.java:18804)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at android.view.View.measure(View.java:18804)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    at android.view.View.measure(View.java:18804)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5954)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
    at android.view.View.measure(View.java:18804)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2112)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1228)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5443)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

也遇到了崩溃问题,

E/Crashlyticscore: Failed to execute task.
java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:177)
    at com.crashlytics.android.core.CrashlyticsBackgroundWorker.submitAndWait(CrashlyticsBackgroundWorker.java:41)
    at com.crashlytics.android.core.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:320)
    at com.crashlytics.android.core.CrashlyticsController$6.onUncaughtException(CrashlyticsController.java:300)
    at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:42)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

如果我恢复到1.0.2版本工作正常.这是一个被注意到的错误吗?如何解决这个问题?

解决方法

我们遇到了同样的问题,问题是新版本添加了一些额外的断言,因此旧代码可能会停止工作,因为约束布局的工作方式,堆栈跟踪根本不直观.
public ConstraintAnchor getAnchor(Type anchorType) {
    switch(anchorType) {
    case LEFT:
    case RIGHT:
        if (this.mOrientation == 1) {
            return this.mAnchor;
        }
        break;
    case TOP:
    case BOTTOM:
        if (this.mOrientation == 0) {
            return this.mAnchor;
        }
        break;
    case BASELINE:
    case CENTER:
    case CENTER_X:
    case CENTER_Y:
    case NONE:
        return null;
    }

    throw new AssertionError(anchorType.name());
}

这是导致异常的方法.检查的是,如果指南是垂直指南,任何为其添加约束的项目都应该横向(开始或结束),反之则为垂直指南.

在我们的例子中,我们使用了布局

app:layout_constraintTop_toBottomOf="@+id/guideline"
app:layout_constraintStart_toStartOf="@+id/guideline"

检查您的布局,并确保在指南中添加适当的约束.

原文链接:/android/314741.html

猜你在找的Android相关文章