Проблема Android ConstraintLayout внутри CardView - PullRequest
0 голосов
/ 24 января 2019

У меня проблема с android.support.constraint.ConstraintLayout внутри android.support.v7.widget.CardView

В основном я хочу вложенный ConstraintLayout

<android.support.constraint.ConstraintLayout>
  <android.support.v7.widget.CardView>
    <android.support.constraint.ConstraintLayout>
       <TextView/>
       <Spinner/>
       <android.support.design.widget.TextInputLayout>
         </EditText>
       <android.support.design.widget.TextInputLayout>
    </android.support.constraint.ConstraintLayout>
  </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>

Тогда я не знаю почему, второй ConstraintLayout ребенок не появляется. Пожалуйста, посмотрите дизайн предварительного просмотра ниже.

enter image description here

Вот полный код

<?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"
    tools:context=".FindTourFragment" android:id="@+id/frameLayout2"
    tools:layout_editor_absoluteY="25dp">

    <include
            layout="@layout/toolbar_main"
            android:id="@+id/job_list_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardCornerRadius="4dp"
            app:layout_constraintTop_toBottomOf="@id/job_list_toolbar">

        <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:orientation="horizontal">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Lokasi"
                    android:id="@+id/textView"
                    android:layout_marginTop="20dp"
                    android:layout_marginStart="20dp"
                    android:layout_marginEnd="20dp"
                    style="@style/InputLabel"

                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="parent"/>

            <Spinner
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:id="@+id/spinner"

                    android:textSize="18sp"
                    android:layout_marginStart="20dp"
                    android:layout_marginEnd="20dp"
                    android:layout_marginTop="15dp"

                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="@id/textView"/>


            <android.support.design.widget.TextInputLayout
                    android:id="@+id/text_input_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:layout_marginBottom="10dp"
                    android:layout_marginStart="20dp"
                    android:layout_marginEnd="20dp"

                    android:textSize="18sp"
                    app:layout_constraintTop_toBottomOf="@+id/spinner"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent">

                <EditText
                        android:hint="Tanggal Keberangkatan"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="date"
                        android:ems="10"
                        android:id="@+id/editText2"
                        android:clickable="true"/>

            </android.support.design.widget.TextInputLayout>
        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.CardView>

    <ListView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/listview"

            app:layout_constraintTop_toBottomOf="@+id/card_view"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>

Ps. Я также попробовал на эмуляторе, тот же результат. Спасибо

1 Ответ

0 голосов
/ 24 января 2019

TextView внутри вашего внутреннего ConstraintLayout имеет этот атрибут:

app:layout_constraintTop_toBottomOf="parent"

Это позиционирует ваш TextView за пределы ConstraintLayout. Поскольку все остальное ограничено этим представлением, все остальное также выходит за пределы ConstraintLayout.

Измените его так, чтобы оно ограничивалось top родительского элемента:

app:layout_constraintTop_toTopOf="parent"
...