安卓CardView显示卡片周围的边框

9
Android cardview在卡片周围显示了不必要的边框。我尝试过多种方法,但无法将其删除。当我给卡片设置自定义背景颜色时,就会出现这种情况。如果删除cardBackgroundColor并使用默认值,则不会显示不必要的边框。
我必须使用阴影和透明颜色代码。
以下是我的CardView布局:
         <RelativeLayout
            android:id="@+id/rlUserNamePassword"
            android:layout_width="match_parent"
            android:background="@android:color/transparent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/margin"
                android:background="@android:color/transparent"
                app:cardBackgroundColor="@color/form_card_bg_color"
                app:cardElevation="@dimen/margin"
                app:contentPadding="@dimen/margin_large"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true" >

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/user" />

                        <android.support.design.widget.TextInputLayout
                            android:id="@+id/tilName"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <com.yaashvi.placeandpeople.customviews.CustomEditText
                                android:id="@+id/etEmail"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:hint="@string/username"
                                android:singleLine="true"
                                android:maxLines="1"/>

                        </android.support.design.widget.TextInputLayout>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/margin_large"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/password" />

                        <android.support.design.widget.TextInputLayout
                            android:id="@+id/tilPassword"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">

                            <com.yaashvi.placeandpeople.customviews.CustomEditText
                                android:id="@+id/etPassword"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:hint="@string/password"
                                android:singleLine="true"
                                android:maxLines="1"
                                android:inputType="textPassword"/>
                        </android.support.design.widget.TextInputLayout>

                    </LinearLayout>
                </LinearLayout>

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

            <LinearLayout
                android:id="@+id/llGo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:orientation="vertical"
                android:elevation="@dimen/margin_large"
                >

                <include layout="@layout/go_button" />

            </LinearLayout>

        </RelativeLayout>

创建的视图如下所示

enter image description here

请注意cardview左侧、右侧和顶部的额外边框以及卡片内部的阴影。


https://dev59.com/3F0b5IYBdhLWcg3wQPbw#A83nnYgBc1ULPQZFxGVV - IntelliJ Amiya
@IntelliJAmiya,它是一个库,因此会增加应用程序的大小。 CardView没有任何删除它的功能吗? - Rakesh Yadav
移除 CardView 的 app:contentPadding 属性,并在 CardView 内部的 LinearLayout 中添加 android:padding 属性...! - Sanjay Chauhan
5个回答

1
尝试这个。
  <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/margin"
                android:background="@android:color/transparent"
                android:elevation="0dp"
                app:cardBackgroundColor="@color/form_card_bg_color"
                app:cardElevation="0dp"
                app:contentPadding="@dimen/margin_large"
                app:cardPreventCornerOverlap="false"
                app:cardUseCompatPadding="true" >

0

我再次检查了一下,我得到了您想要的结果。<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimay >


0

尝试在XML代码中添加card_view:cardPreventCornerOverlap="false"


0
对我来说,额外的边框看起来就像是你的RelativeLayout的背景。我需要看到布局的完整代码才能确认,但如果我是正确的,这意味着你在某个地方可能以编程方式更改了你在这里定义的RelativeLayout的透明背景。

please share the full layout code. thanks

         <RelativeLayout
            android:id="@+id/rlUserNamePassword"
            android:layout_width="match_parent"
            android:background="@android:color/transparent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.CardView...


0

以下的方法都没有真正地对我起作用

真正起作用的是将内部图像的宽度和高度增加2dp。

例如:

<androidx.cardview.widget.CardView
android:layout_width="25dp"
android:layout_height="25dp"
app:cardCornerRadius="260dp"
app:cardElevation="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
  android:id="@+id/image2"
  android:layout_width="27dp"
  android:layout_height="27dp"
  android:src="@drawable/test" />

</androidx.cardview.widget.CardView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接