首页 > 解决方案 > CardView for Android 9.0 有空格黑空白,怎么去掉黑空格

问题描述

CardView for Android 有空格,如何去除。我需要帮助。这是java或android问题。

在此处输入图像描述

<android.support.v7.widget.CardView
                android:id="@+id/cv_result_knowledge"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll_result_header"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:visibility="gone"
                app:cardBackgroundColor="@color/black_transparent40"
                app:cardCornerRadius="@dimen/d12"
                app:cardElevation="@dimen/d1"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/d10"
                    android:layout_marginTop="@dimen/d2">



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

标签: androidkotlin

解决方案


这是因为您将背景颜色设置为黑色,您的相对布局设置了边距,因此黑色卡片背景在边距区域中可见。只需删除卡片背景或删除边距,以适合您的方式。

<android.support.v7.widget.CardView
                android:id="@+id/cv_result_knowledge"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll_result_header"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:visibility="gone"
                app:cardBackgroundColor="@color/black_transparent40" -<REMOVE THIS
                app:cardCornerRadius="@dimen/d12"
                app:cardElevation="@dimen/d1"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/d10" -<REMOVE THIS
                    android:layout_marginTop="@dimen/d2">    -<REMOVE THIS


推荐阅读