【问题标题】:Nested layout inside CardView overlaps parent endCardView 内的嵌套布局与父端重叠
【发布时间】: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_ofend_to_end_of设置为parent,意思是ConstraintLayout。但是单看视图的顶部,似乎也有空间让这个 xml 更简单,只需重新组织一下。

标签: android android-layout


【解决方案1】:

您需要将 Linearlayout 高度更改为 ma​​tch-parent 而不是 wrap_content。使用 wrap_content,您不会将 Linearlayout 视图的大小限制为 CardView 的大小。

           <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 2013-08-22
    • 2013-06-02
    • 1970-01-01
    相关资源
    最近更新 更多