我在 RecyclerView 中使用 CardView 作为元素。这样做时,android 会自动在 cardView 和屏幕之间以及不同 cardView 之间生成边距。
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/galleryCardBGColor"
app:cardCornerRadius="2dp" >
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
我按照链接中的说明将它们集成到我的项目中: using-recyclerview-and-cardview-in-eclipse-adt
我之前一直在为列表元素使用线性布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
这工作得很好,列表元素之间没有任何边距。我现在刚刚将线性布局放置在 cardView 中,这导致了额外的边距。
原因是我想为这些元素提供准确的边距,并且我现在提供的任何边距都被添加到这个预先存在的边距中。我尝试为 cardView 元素提供零/负填充/边距,但这些都不起作用。
任何想法,我都可以删除这些边距,或者确切地知道要添加多少边距。