我在 android.support.v7.widget.CardView
中的 android.support.constraint.ConstraintLayout
上有问题
基本上我想嵌套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
child没有出现。请看下面的预览设计。
完整代码如下
<?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>
附言。我也试过模拟器,同样的结果。谢谢
最佳答案
内部 ConstraintLayout
中的 TextView
具有此属性:
app:layout_constraintTop_toBottomOf="parent"
这会将您的 TextView 定位在 ConstraintLayout 的边界之外。由于其他所有内容都受限于此 View ,因此其他所有内容也在 ConstraintLayout 的范围之外。
改为将其限制在父级的顶部:
app:layout_constraintTop_toTopOf="parent"
关于CardView 中的 Android ConstraintLayout 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54351614/