我想問你,如果你有約束佈局的類似問題。片段元素包含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>
當片段佈局中使用活動直接,一切都很好。