我正在将CardView作为RecyclerView中的元素使用。这样做时,Android会自动在卡片视图与屏幕之间以及不同卡片视图之间生成边距。
<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" />
我按照链接中的指示将它们集成到我的项目中:在Eclipse ADT中使用RecyclerView和CardView
之前我一直使用LinearLayout来作为列表元素:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
这原本完全正常运作,列表元素之间毫无边距。现在我把线性布局放到卡片视图里面,结果出现了额外的边距。
原因是我想为这些元素提供精确的边距,而现在提供的任何边距都被添加到这些已有的边距上。 我尝试向cardView元素提供零/负填充/边距,但它们都无法解决问题。
有什么建议可以消除这些边距或者知道被添加了多少边距吗?