【发布时间】:2019-10-11 05:42:31
【问题描述】:
我不知道这是怎么发生的,但我有一个 ConstraintLayout,里面有一个 CardView。里面说CardView是一个LinearLayout。该 LinearLayout 与最后的父级重叠。查看屏幕截图以获取更多信息。如果我从 cardView 中删除 android:layout_margin,内部布局看起来又不错了,但是在开始时添加边距似乎只是将整个布局推到父级的末尾并越过父级的末尾。在 CardView 中使用哪种布局并不重要。这个问题影响到他们所有人。
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@color/colorWhite">
..
<androidx.cardview.widget.CardView
android:id="@+id/wakeuptimer_status_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/md_keylines"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
.....
【问题讨论】:
-
当你可以使用 Constraint-layout 将整个内容映射到其中时,为什么要使用 LinearLayout
-
旧习惯。此外,在 CardView 中使用 ConstraintLayout 也会导致同样的问题。无论如何,似乎问题在于卡片视图中的边距。如果我从 cardView 中删除 android:layout_margin,内部布局又看起来不错。很奇怪。
-
好像
CardView需要将start_to_start_of和end_to_end_of设置为parent,意思是ConstraintLayout。但是单看视图的顶部,似乎也有空间让这个 xml 更简单,只需重新组织一下。