카테고리 없음

[안드로이드] CardView에서 비정형 이미지 네모 박스 보일때

킹왕짱지지 2024. 8. 15. 21:17

1. 오류 상황

- 나는 저 이모지들이 그냥 이모지 자체로 존재하길 바라는데 자꾸만 흰 배경이 보임. background 색을 transparent줬는데도 그럼

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@android:color/transparent"
android:clickable="true"
android:focusable="true"
android:padding="4dp"
tools:ignore="SpeakableTextPresentCheck">


<ImageView
    android:id="@+id/imageView"
    android:layout_width="50sp"
    android:layout_height="50sp"
    android:scaleType="centerCrop" />
</androidx.cardview.widget.CardView>

 

 

2. 해결방법

android:background="@android:color/transparent"로 설정하는게 아님. 

CardView의 기본 배경이 있는 경우가 있음. 

c

ardBackgroundColor를 transparent 로 설정해야함! 

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_margin="4dp"
    android:clickable="true"
    android:focusable="true"
    android:padding="4dp"
    app:cardBackgroundColor="@android:color/transparent"
    app:cardElevation="0dp"
    tools:ignore="SpeakableTextPresentCheck">



<ImageView
        android:id="@+id/imageView"
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:scaleType="centerCrop" />
</androidx.cardview.widget.CardView>