Подтвердить что ты не робот

Android CardView с закругленными углами отображает серые углы

Я раздуваю пользовательский макет с помощью CardView внутри макета. Закругленные углы отображаются, как и ожидалось, но за углами у меня также появляется серый фон.

Код прост, использует CardView с угловым радиусом и цветом фона. Я пытался установить прозрачный фон, но не работает. Однако, если я установлю другой непрозрачный цвет, он будет отображаться в углах.

Код прилагается.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@android:color/white"
        app:cardCornerRadius="6dp"
        app:cardElevation="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent">

            <TextView
                android:id="@+id/tvProgress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/ivIcon"
                android:layout_toStartOf="@+id/ivIcon"
                android:background="@android:color/transparent"
                android:padding="@dimen/elementPaddingSmall"
                android:text="Initial Discussion"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@android:color/black" />

            <ImageView
                android:id="@+id/ivIcon"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:background="@color/lightBrown"
                android:scaleType="centerInside"
                android:src="@drawable/ic_checkmark_circle" />
        </RelativeLayout>


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

Результат:

enter image description here

4b9b3361

Ответ 1

Это из-за тени, вам нужно предоставить пространство для просмотра, чтобы показать полную тень. Добавьте android:layout_margin="5dp" в CardView, и вы увидите, что "серый" цвет обрезается.

Решение добавляет app:cardUseCompatPadding="true" в CardView, и это даст необходимый интервал.

Ответ 2

Попробуй это...

Просто установите значение 0 для приложения: cardElevation

.....
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="6dp"
    app:cardElevation="0dp">
.....

ИЛИ вы можете вызвать cardView.setCardElevation(0), чтобы программно отключить тень.

Ответ 3

Удалите родительский RelativeLayout который обертывает CardView и вам хорошо идти. Именно так:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="6dp"
    app:cardElevation="5dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

        <TextView
            android:id="@+id/tvProgress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/ivIcon"
            android:layout_toStartOf="@+id/ivIcon"
            android:background="@android:color/transparent"
            android:padding="@dimen/elementPaddingSmall"
            android:text="Initial Discussion"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"/>

        <ImageView
            android:id="@+id/ivIcon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:background="@color/lightBrown"
            android:scaleType="centerInside"
            android:src="@drawable/ic_checkmark_circle"/>
    </RelativeLayout>


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

Ответ 4

Если кто-то сталкивается с проблемой, когда цвет краев темнее, чем вы установили, это может произойти, если вы установите цвет в формате #AARRGGBB. Чтобы устранить эту проблему, просто установите цвет в обычном формате #RRGGBB.

Ответ 5

Измените app:cardUseCompatPadding="true" на card_view:cardUseCompatPadding="true"