Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint layout Issue java.lang.AssertionError: TOP

I started using Constraint Layout, I facing Assertion Error while compiling the design file alone this issue will occur. What is the right way to fix this issue? I mess up with hole day. Here is my XML design.

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

And My Error Log here:

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:1597) at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1031) at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:794) at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1542) at android.view.View.measure(View.java:21051) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141) at android.view.View.measure(View.java:21051) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:21051) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at android.view.View.measure(View.java:21051) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) at android.view.View.measure(View.java:21051) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) at com.android.internal.policy.DecorView.onMeasure(DecorView.java:849) at android.view.View.measure(View.java:21051) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2583) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1642) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1893) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1522) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7098) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927) at android.view.Choreographer.doCallbacks(Choreographer.java:702) at android.view.Choreographer.doFrame(Choreographer.java:638) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

like image 915
MohanRaj S Avatar asked Jul 30 '18 12:07

MohanRaj S


3 Answers

When you use a vertical guideline, any view constrained to it should do it horizontally and same thing for horizontal guidelines.

In your case, your are constraining view_template_1 vertically to a vertical guideline so change this :

app:layout_constraintBottom_toTopOf="@+id/gL_right_margin"

by a horizontal guideline

Always check your layouts and make sure you add the proper constraint to a guideline.

like image 105
Belbahar Raouf Avatar answered Oct 21 '22 22:10

Belbahar Raouf


I was missing the android:orientation="horizontal" / android:orientation="vertical" tag from the GuideLine. Make sure you have added it correctly.

Finally, it should look like this

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/gl_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="@id/cv_rank_status"
        app:layout_constraintGuide_percent="0.3"
        app:layout_constraintTop_toTopOf="@id/cv_rank_status" />
like image 36
iCantC Avatar answered Oct 21 '22 23:10

iCantC


Try to remove plus symbol from referencing your guidelines. For example here app:layout_constraintEnd_toStartOf="@+id/gL_image_size_margin"

like image 2
Yoric Avatar answered Oct 21 '22 22:10

Yoric