当前位置: 首页 > 知识库问答 >
问题:

约束布局问题java.lang.AssertionError:TOP

西门磊
2023-03-14

我刚开始使用约束布局,我在编译设计文件时遇到断言错误,这个问题就会单独出现。解决此问题的正确方法是什么?我搞砸了洞日。这是我的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:id="@+id/cL_Layout"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:background="@color/card_background">

    <android.support.constraint.Guideline
        android:id="@+id/gL_right_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.95" />

    <android.support.constraint.Guideline
        android:id="@+id/gL_vertical_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.50364965" />
    <android.support.constraint.Guideline
        android:id="@+id/gL_bottom_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="1.0" />

    <android.support.constraint.Guideline
        android:id="@+id/gL_image_size_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.3" />


    <ImageView
        android:id="@+id/imgVw_AddClips_recVw_icon"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="4dp"
        android:layout_marginStart="4dp"
        android:layout_marginTop="4dp"
        android:adjustViewBounds="true"
        android:background="@drawable/qik_highlights_shape"
        android:contentDescription="@string/dummy_content"
        android:scaleType="fitCenter"
        android:src="@drawable/bg_cloud_icon"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/gL_image_size_margin"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <com.ibot.cyranoapp.customview.TextViewFont
        android:id="@+id/txtIp_recVw_AddClips_Name_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/recVw_Template_channel"
        android:textAllCaps="false"
        android:textColor="@color/fa_preview_button_text_grey"
        android:textSize="14sp"
        android:textStyle="bold"
        app:layout_constraintStart_toEndOf="@+id/gL_image_size_margin"
        app:layout_constraintTop_toTopOf="parent" />


    <com.ibot.cyranoapp.customview.TextViewFont
        android:id="@+id/txtIp_recVw_Components_Name_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_marginStart="8dp"
        android:text="@string/recVw_Template_Components"
        android:textAllCaps="false"
        android:textColor="@color/fa_preview_button_text_grey"
        android:textSize="12sp"
        app:layout_constraintStart_toEndOf="@+id/gL_image_size_margin"
        app:layout_constraintTop_toBottomOf="@+id/txtIp_recVw_AddClips_Name_title" />

    <com.ibot.cyranoapp.customview.TextViewFont
        android:id="@+id/txtIp_recVw_channel_subscribers_hint"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:text="@string/channel_subscribers"
        android:textAllCaps="false"
        android:textColor="@color/fa_preview_button_text_grey"
        android:textSize="12sp"
        app:layout_constraintStart_toEndOf="@+id/gL_image_size_margin"
        app:layout_constraintTop_toBottomOf="@+id/txtIp_recVw_Components_Name_title" />


    <RadioButton
        android:id="@+id/rBtn_AddClips_SelectionIcon"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:button="@drawable/qik_checkbox"
        android:text="@null"
        android:theme="@null"
        app:layout_constraintBottom_toTopOf="@+id/gL_bottom_margin"
        app:layout_constraintEnd_toStartOf="@+id/gL_right_margin"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_template_1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/fa_preview_button_text_grey"
        android:visibility="gone"
        app:layout_constraintBottom_toTopOf="@+id/gL_right_margin"
        app:layout_constraintEnd_toEndOf="@+id/gL_right_margin" />

    <View
        android:id="@+id/view_template_selection"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/fa_green_1"
        app:layout_constraintBottom_toBottomOf="@+id/view_template_1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

和我的错误日志:

java.lang.AssertionError:在Android.Support.Constraint.Solver.Widgets.Guideline.GetAnchor(Guideline.java:159)在Android.Support.Constraint.ConstraintLayout.SetChildRenConstraints(ConstraintLayout.1031)在Android.Support.Constraint.ConstraintLayout.UpdateHierarchy(ConstraintLayout.794)在Android.Support.Constraint.ConstraintLayout.OnMeasure(ical(LinearLayout.java:758)位于Android.Widget.LinearLayout.OnMeasure(LinearLayout.java:640)位于Android.View.View.View.Measure(View.java:21051)位于Android.Widget.FrameLayout.OnMeasure(FrameLayout.java:6459)位于Android.Widget.FrameLayout.OnMeasure(FrameLayout.java:185)位于Android.View.View.FrameLayout.Measure(View.java在Android.View.ViewRootimpl.PerformTraversals(viewRootimpl.java:1893)在Android.View.ViewRootimpl.DoTraversal(viewRootimpl.java:1522)在Android.View.ViewRootimpl$TraversalRunnable.Run(viewRootimpl.java:7098)在Android.View.Choreographer$CallbackRecord.Run(choreographer.Docallbacks(choreographer.java:927)在

共有1个答案

孙渝
2023-03-14

当您使用垂直指南时,任何受其约束的视图都应该水平地执行该操作,对于水平指南也是同样的操作。

在您的示例中,您将view_template_1垂直约束为垂直准则,因此更改以下内容:

app:layout_constraintBottom_toTopOf="@+id/gL_right_margin"

通过横向指导方针

总是检查您的布局,并确保您添加了适当的约束到指导原则。

 类似资料:
  • 我是android编程的新手,我还不知道很多事情。我在这里试图实现的是这样的东西。如果用户没有互联网连接,广告不会显示,或者如果广告由于某种原因没有加载,那么广告不会显示。但布局保持不变,这意味着广告空间是空的。我所做的是在一个相对的布局内扭曲广告视图,然后创建了一个函数,检查广告是否被加载,然后改变布局的可见性,这似乎工作,并解决了当广告不加载时的空白问题。但我认为这不是最好的方法,必须有更好的

  • 我有两个组件和。每个组件都是由<code>ConstraintLayout</code>创建的。现在,我从上面的组件创建<code>WelcomeScreen</code>。 用例1:使用静态< code>ConstraintLayout(在< code>ConstraintLayout内的< code>ConstraintLayout) 结果:布局预览不显示任何内容 用例2:<代码>Welcom

  • 我使用约束布局来设计UI。问题是,对于5英寸到5.5英寸的屏幕(这意味着1080x1920 dpi到1440x2560 dpi),设计看起来不错,但是当我将3.7英寸的屏幕切换到4.7英寸的屏幕(480x800 dpi到768x1280 dpi)时,问题就出现了已经不见了。 那么,如何使用约束布局响应所有设备屏幕的UI设计? 5英寸至5.5英寸屏幕(即1080x1920 dpi至1440x2560

  • 我的约束布局的版本是。在我的布局中包含了一个工具栏之后,工具栏的左右两边都有空间,如下图所示 这是我的工具栏的代码 我以以下方式将其包含在我的布局中 我没有在布局文件的根元素中使用任何附加的填充或边距。 另一个奇怪的事情是,如果我编译或构建程序,我的代码会自动改变,比如 更改为

  • 我正在学习布局。我不熟悉布局。我读了一些教程,对布局有了很好的了解。但当我尝试实现布局时,我正在努力适应所有屏幕。在这里,我附上了我的样本屏幕。我正在设计一个登录屏幕。我想让这种设计适合所有的屏幕。 当我在5英寸或6英寸的屏幕上看到这个设计时,它看起来不错。但当我看到4.7或更低的屏幕尺寸时,它不适合屏幕。请让我知道如何对所有屏幕大小使用约束布局。请为本课程提供一些示例/教程。