EditText,当转到多行时,会搞乱Constraint Layout android

时间:2018-01-11 17:51:21

标签: android android-layout android-constraintlayout

我有一个使用约束布局的片段。布局看起来很好,直到编辑文本进行换行,然后底部的两个片段元素向上移动到编辑文本中。我没有看到约束布局有任何问题。这是布局:

<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/task_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/task_base_buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/task_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="50dp"
            android:gravity="center"
            android:textColor="@color/black"
            android:textSize="@dimen/title_font_size"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Title" />

        <TextView
            android:id="@+id/task_subtitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/task_title"
            android:layout_centerHorizontal="true"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="17dp"
            android:gravity="center"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/task_title"
            tools:text="Subtitle" />

        <TextView
            android:id="@+id/task_description"
            android:layout_width="match_parent"
            android:layout_height="21dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:gravity="center_horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/task_subtitle"
            tools:text="Description" />

<FrameLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/task_placeholder"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="40dp"
android:paddingBottom="40dp"
android:paddingStart="37dp"
android:paddingEnd="37dp">

<EditText
    android:id="@+id/task_editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:text="Some text"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textMultiLine"
    android:cursorVisible="true"
    />

  </FrameLayout>

        <TextView
            android:id="@+id/freeFormTextLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            android:layout_marginTop="44dp"
            app:layout_constraintBottom_toTopOf="@id/freeFormText"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/task_placeholder"
            tools:text="Free Form Label" />

        <EditText
            android:id="@+id/freeFormText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            tools:hint="Free from text hint" />

    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.constraint.ConstraintLayout
    android:id="@+id/task_base_buttons"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btnTaskBack"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_back"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

    <Button
        android:id="@+id/btnTaskContinue"
        style="@style/NeutrifProText.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_weight="0.6"
        android:background="@drawable/rounded_rect_color_primary"
        android:text="@string/action_continue"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btnTaskSkip"
        app:layout_constraintStart_toEndOf="@+id/btnTaskBack" />

    <Button
        android:id="@+id/btnTaskSkip"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_skip"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

</android.support.constraint.ConstraintLayout>

<View
    android:id="@+id/overview_click_interceptor"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</android.support.constraint.ConstraintLayout>

这是换行前的图像:

unwrapped text

换行后:

messed up text

1 个答案:

答案 0 :(得分:1)

我在混音中添加了一个LinearLayout,它都完美无缺。将constraintLayout库更新为1.1.0-beta4打破了其他一些东西。

<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/task_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/task_base_buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/task_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="50dp"
            android:gravity="center"
            android:textColor="@color/black"
            android:textSize="@dimen/title_font_size"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Title" />

        <TextView
            android:id="@+id/task_subtitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/task_title"
            android:layout_centerHorizontal="true"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="17dp"
            android:gravity="center"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/task_title"
            tools:text="Subtitle" />

        <TextView
            android:id="@+id/task_description"
            android:layout_width="match_parent"
            android:layout_height="21dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:gravity="center_horizontal"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/task_subtitle"
            app:layout_constraintBottom_toTopOf="@id/task_data"
            tools:text="Description" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/task_data"
            app:layout_constraintBottom_toTopOf="@id/freeFormTextLabel"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/task_description"
            >

        <FrameLayout 

         android:layout_width="match_parent"
         android:layout_height="match_parent"
         xmlns:tools="http://schemas.android.com/tools"
         android:paddingTop="52dp"
         android:paddingBottom="52dp"
         android:paddingStart="37dp"
         android:paddingEnd="37dp">

      <EditText
         android:id="@+id/task_editText"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         tools:text="Some text"
         />

      </FrameLayout>
        </LinearLayout>

        <TextView
            android:id="@+id/freeFormTextLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            android:layout_marginTop="44dp"
            app:layout_constraintBottom_toTopOf="@id/freeFormText"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/task_data"
            tools:text="Free Form Label" />

        <EditText
            android:id="@+id/freeFormText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="12dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            tools:hint="Free from text hint" />

    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

<android.support.constraint.ConstraintLayout
    android:id="@+id/task_base_buttons"
    android:layout_width="match_parent"
    android:layout_height="66dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <Button
        android:id="@+id/btnTaskBack"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_back"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

    <Button
        android:id="@+id/btnTaskContinue"
        style="@style/NeutrifProText.Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_weight="0.6"
        android:background="@drawable/rounded_rect_color_primary"
        android:text="@string/action_continue"
        android:textColor="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btnTaskSkip"
        app:layout_constraintStart_toEndOf="@+id/btnTaskBack" />

    <Button
        android:id="@+id/btnTaskSkip"
        style="@style/NeutrifProText.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_weight="0.2"
        android:background="@android:color/transparent"
        android:text="@string/action_skip"
        android:textColor="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="@+id/btnTaskContinue"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnTaskContinue" />

</android.support.constraint.ConstraintLayout>

<View
    android:id="@+id/overview_click_interceptor"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />