CardView内RecyclerView有额外的利润 [英] CardView inside RecyclerView has extra margins

查看:194
本文介绍了CardView内RecyclerView有额外的利润的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是CardView作为RecyclerView内的元素。当这样做的android自动生成cardView和屏幕之间和不同cardViews的利润。

I am using a CardView as element inside a RecyclerView. When doing so android automatically generates margins between the cardView and the screen and between different cardViews.

<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" />

我跟着他们融入我的项目的链接的说明: <一href="http://happily$c$cd.com/blog/using-recyclerview-and-cardview-in-eclipse-adt/">using-recyclerview-and-cardview-in-eclipse-adt

I followed the instructions in the link to integrate them into my project: using-recyclerview-and-cardview-in-eclipse-adt

我一直pviously使用的LinearLayout的列表元素$ P $:

I had been previously using a linearlayout for the list element :

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

这是工作完全正常,有没有任何利润的列表元素之间。我现在刚放置的cardView内的线性布局而导致的额外利润。

This was working perfectly fine, with no margins whatsoever between the list elements. I have now just placed the linear layout inside the cardView which has resulted in extra margins.

原因是,我想提供确切的利润率将这些元素,我现在提供任何利润将被加入到这条preexisting利润。 我曾尝试提供零/负的补白/利润率为cardView元素,但所有这些工作。

The reason being that i want to provide exact margins to these elements, and any margins I supply now is being added over to this preexisting margins. I have tried supplying zero/negative paddings/margins to the cardView element but none of these work.

任何想法,我可以删除这些保证金或以其他方式知道到底有多少保证金将被添加。

Any idea, I can remove these margins or otherwise know exactly how much margin is being added.

推荐答案

你检查它是否是保证金或填充? (开发选项/显示布局界限)

did you check if it is margin or padding? (Dev Options / show layout bounds)

CardView添加填充在平台上preL绘制阴影。在L,除非你设置useCompatPadding =真,不应该有任何间隙。

CardView adds padding in platforms pre-L to draw shadows. In L, unless you set useCompatPadding=true, there should not be any gap.

添加切缘阴性(虽然它是丑陋的)应该工作。如果不是,请添加上你是如何加入他们,你是如何建立RecyclerView一些code。

Adding negative margins (although it is ugly) should work. If it is not, please add some more code on how you are adding them and how you are setting up the RecyclerView.

这篇关于CardView内RecyclerView有额外的利润的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆