我是否可以使用约束布局的子布局,这也是约束布局?在工具栏里面似乎没问题,但是当我直接添加父约束布局的约束布局时,我得到关于约束布局未找到的类的错误消息等等。我尝试将constaint布局放在FrameLayout内并且在LinearLayout内但是这没有摆脱错误?那么它是否可能,如果是这样,我该怎么做呢?
答案 0 :(得分:1)
是的,你可以嵌套ConstraintLayouts,我只是没有任何问题。我建议你仔细检查你的语法。嵌套时ClassNotFoundException确实没有任何意义。
答案 1 :(得分:0)
您可以肯定地嵌套ConstraintLayouts,constraintLayout的主要优点之一是,与其他布局相比,它为您提供所需的布局,并且嵌套最少。您必须检查所用的代码和语法,这不成问题,因为的ConstraintLayout嵌套。
这是我的代码,我在ConstraintLayout中使用了ConstraintLayout,没有任何错误:
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="376dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button3"
android:layout_width="171dp"
android:layout_height="78dp"
android:layout_marginBottom="92dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.566"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="155dp"
android:layout_height="59dp"
android:layout_marginTop="68dp"
android:text="Test"
android:textSize="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.593"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>