我开始使用约束布局,在仅编译设计文件时遇到断言错误,将发生此问题。解决此问题的正确方法是什么?我搞砸了一天。这是我的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:TOP 在android.support.constraint.solver.widgets.Guideline.getAnchor(Guideline.java:159) 在android.support.constraint.solver.widgets.ConstraintWidget.immediateConnect(ConstraintWidget.java:1597) 在android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1031) 在android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:794) 在android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1542) 在android.view.View.measure(View.java:21051) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141) 在android.view.View.measure(View.java:21051) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) 在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 在android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 在android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 在android.view.View.measure(View.java:21051) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在android.view.View.measure(View.java:21051) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) 在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 在android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 在android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 在android.view.View.measure(View.java:21051) 在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6459) 在android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 在com.android.internal.policy.DecorView.onMeasure(DecorView.java:849) 在android.view.View.measure(View.java:21051) 在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2583) 在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1642) 在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.java:927) 在android.view.Choreographer.doCallbacks(Choreographer.java:702) 在android.view.Choreographer.doFrame(Choreographer.java:638) 在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:913) 在android.os.Handler.handleCallback(Handler.java:751) 在android.os.Handler.dispatchMessage(Handler.java:95) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6682) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
答案 0 :(得分:7)
使用垂直参考线时,任何受其限制的视图都应水平执行,而对于水平参考线也应如此。
您的情况是,您将Makefile
垂直限制为垂直准则,因此请更改此内容:
view_template_1
根据水平准则
始终检查布局,并确保在准则中添加适当的约束。
答案 1 :(得分:3)
我丢失了android:orientation="horizontal"
中的android:orientation="vertical"
/ GuideLine
标签。确保已正确添加。
最后,它应该看起来像这样
<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" />
答案 2 :(得分:1)
尝试从参考指南中删除加号。例如这里app:layout_constraintEnd_toStartOf="@+id/gL_image_size_margin"