边距的影响?

Effect with margins?

设计是一个线性布局,里面有一个卡片和一个背景色,就这么简单。

通过单击任何视图(视图 1、视图 2 ...),将动态添加其他布局。这些新布局 "push" 包含 Cardview 的 Linearlayout。我觉得这不影响我想要达到的效果

我想得到你在下一张图片中看到的效果。

有什么想法吗?

为此你需要使用 ConstraintLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

  <android.support.v7.widget.CardView
    android:id="@+id/abc"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    app:layout_constraintTop_toTopOf="linearLayout"
    app:layout_constraintBottom_toTopOf="linearLayout"/>

   <LinearLayout>
   ....Your Layout Code.....
   </LinearLayout/>

</android.support.constraint.ConstraintLayout>