【问题标题】:android cardview showing border around cardandroid cardview显示卡周围的边框
【发布时间】:2017-12-11 09:16:06
【问题描述】:

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>

创建的视图是这样的

查看卡片视图左侧、右侧和顶部以及卡片阴影内的额外边框。

【问题讨论】:

  • @IntelliJAmiya,它是一个库,因此会增加应用程序的大小。卡片视图没有任何功能可以删除它吗?
  • 移除 CardView app:contentPadding 并在 CardView 内部的 LinearLayout 中添加 android:padding ...!

标签: android shadow android-cardview box-shadow cardview


【解决方案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" >

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      尝试将card_view:cardPreventCornerOverlap="false" 添加到 XML 代码

      【讨论】:

        【解决方案4】:

        对我来说,额外的边框似乎只是您的 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...

        【讨论】:

          【解决方案5】:

          以下没有一个真正适合我

          起作用的是使内部图像的宽度和高度 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>
          

          【讨论】:

            猜你喜欢
            • 2015-06-06
            • 1970-01-01
            • 2021-12-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-09-09
            • 2013-09-11
            • 2011-06-12
            相关资源
            最近更新 更多