我想问你,如果你对约束布局有类似的问题。当片段元素包含 id 标记时,片段的格式不正确。
我的活动只有一个在 xml 中定义的片段:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/initial__initial_fragment"
android:name="com.touch4it.taxi.screens.initial.InitialFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/initial__fragment__layout" />
片段约束一约束布局:
<?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/initial__fragment__layout__holder_CL"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/initial__fragment__layout__phone_number_ET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:text="Name"
android:singleLine="true"
app:layout_constraintLeft_toLeftOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/initial__fragment__layout__user_name_ET"
android:layout_marginTop="48dp"
app:layout_constraintRight_toRightOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginEnd="16dp" />
<EditText
android:id="@+id/initial__fragment__layout__user_name_ET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
android:singleLine="true"
app:layout_constraintLeft_toLeftOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/initial__fragment__layout__log_in_label_TV"
android:layout_marginTop="64dp"
app:layout_constraintRight_toRightOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginEnd="16dp" />
<Button
android:id="@+id/initial__fragment__layout__login_B"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintLeft_toLeftOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginStart="16dp"
app:layout_constraintRight_toRightOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginBottom="16dp" />
<TextView
android:id="@+id/initial__fragment__layout__log_in_label_TV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginStart="16dp"
app:layout_constraintTop_toTopOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginTop="48dp"
app:layout_constraintRight_toRightOf="@+id/initial__fragment__layout__holder_CL"
android:layout_marginEnd="16dp" />
</android.support.constraint.ConstraintLayout>
直接在activity中使用fragment layout时,一切正常。