android cardview showing border around card
Asked Answered
A

5

9

Android cardview is showing unnecessary border around the card. I have tried different things but I am not able to remove it. It happens when I give the card a custom background color. When I remove the cardBackgroundColor, and when default is used. Then unnecessary border is not visible.

I have to use shadow and tranparent color code.

Here is my layout 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>

And the view created is this

enter image description here

See the extra border on left, right and top of cardview and inside the card shadow.

Adequacy answered 7/7, 2017 at 7:7 Comment(3)
#29393263Acheron
@IntelliJAmiya, it is a library, so will increase size of the app. Doesn't the cardview have any feature to remove this?Adequacy
remove CardView app:contentPadding and add the android:padding in LinearLayout of inside the CardView ...!Parlous
A
1

try this.

  <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" >
Arrack answered 7/7, 2017 at 9:15 Comment(0)
G
0

i check it again and i got that result what you want.<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimay >

Greenhouse answered 7/7, 2017 at 10:18 Comment(0)
M
0

try adding card_view:cardPreventCornerOverlap="false" to XML code

Modena answered 31/5, 2020 at 10:1 Comment(0)
K
0

For me, it looks like that extra border is just the background of your RelativeLayout. I need to see the full code of the layout to confirm but if I'm right, this means somewhere maybe programmatically your changing the transparent background of the RelativeLayout that you defined here

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...
Kovno answered 31/5, 2020 at 10:50 Comment(0)
S
0

none of the following truly worked for me

what did work was making the inner image width and height 2dp bigger. example:

<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>
Storeroom answered 6/9, 2020 at 4:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.