Java CardView填充/间距因API级别而异

Java CardView填充/间距因API级别而异,java,android,xml,android-studio,android-cardview,Java,Android,Xml,Android Studio,Android Cardview,我正在多个设备上测试我的应用程序,并注意到使用CardView时,某些设备正在渲染每个CardView之间的间距 我试图隔离问题,看起来API 23不包含任何间距,而API

我正在多个设备上测试我的应用程序,并注意到使用CardView时,某些设备正在渲染每个CardView之间的间距

我试图隔离问题,看起来API 23不包含任何间距,而API<23呈现某种填充/间距

请注意,我已经尝试了所提出的解决方案,但它不起作用。它在XML中提出了以下建议:

app:cardUseCompatPadding="true"
API 23

空气污染指数<23


问题在于,在api-21和更高版本上,CardView本机受支持,而在KitKat和更早版本上,CardView则被支持库伪造

我过去成功的做法是使用单独的布局文件,只需手动像素推送它们,直到看起来合适为止

例如,在res/layout中,您有以下xml:

<android.support.v7.widget.CardView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:cardview="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/my_card"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_marginRight="0dip"
     android:layout_marginLeft="0dip"
     android:layout_marginTop="1dip"
     android:layout_marginBottom="1dip"
     cardview:cardBackgroundColor="@color/even_light_gray"
     android:foreground="@drawable/card_foreground"
     cardview:cardCornerRadius="1dp" >

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="8dp"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:paddingTop="4dp" >

        <!-- .......... -->

        </LinearLayout>
</android.support.v7.widget.CardView>

问题在于,在api-21和更高版本上,CardView本机受支持,而在KitKat和更早版本上,CardView则被支持库伪造

我过去成功的做法是使用单独的布局文件,只需手动像素推送它们,直到看起来合适为止

例如,在res/layout中,您有以下xml:

<android.support.v7.widget.CardView
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:cardview="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/my_card"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_marginRight="0dip"
     android:layout_marginLeft="0dip"
     android:layout_marginTop="1dip"
     android:layout_marginBottom="1dip"
     cardview:cardBackgroundColor="@color/even_light_gray"
     android:foreground="@drawable/card_foreground"
     cardview:cardCornerRadius="1dp" >

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="8dp"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:paddingTop="4dp" >

        <!-- .......... -->

        </LinearLayout>
</android.support.v7.widget.CardView>
我发现这个。。。 在cardview属性中使用此选项, 应用:cardPreventCornerOverlap=false 并在不同的android操作系统版本中使用它 应用程序:cardMaxElevation=0dp app:cardElevation=0dp 在pre-L中,使其为0dp,在api21或之后,使其为非零

我发现。。。 在cardview属性中使用此选项, 应用:cardPreventCornerOverlap=false 并在不同的android操作系统版本中使用它 应用程序:cardMaxElevation=0dp app:cardElevation=0dp
在pre-L中,将它们设为0dp,在api21或之后,将它们设为非零

此XML是否允许在CardView上不进行填充?最后,我试图删除所有API级别上的填充…实际上,看起来您可能根本不想使用CardView。通常在需要角半径和高程时使用CardView,而您甚至没有使用它。尝试使用LinearLayout或RelativeLayout而不是CardView。此XML是否允许在CardView上没有填充?最后,我试图删除所有API级别上的填充…实际上,看起来您可能根本不想使用CardView。通常在需要角半径和高程时使用CardView,而您甚至没有使用它。尝试只使用LinearLayout或RelativeLayout而不是CardView。