Archives
Recent Posts
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Today
Total
관리 메뉴

안드로이드 개발자의 창고

[31일차 Android] CardView 본문

Computer/Android

[31일차 Android] CardView

Wise-99 2023. 6. 14. 17:47

 

 

 

출처 : 안드로이드 앱스쿨 2기 윤재성 강사님 수업 PPT

 

 

 

📖 CardView

  • 화면에 배치되는 View들을 그룹으로 묶어 관리할 수 있는 View
  • CardView 자체에 그림자를 두어 약간 공중에 떠있는 듯한 모습을 만들 수 있다.

주요 속성

속성
설명
contentPadding
CardView 내부의 여백을 설정
cardCornerRadius
CardView 모서리 부분의 둥근 정도를 설정
cardElevation
CardView가 공중에 떠있는 정도를 설정

 

 

 

예제 코드

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    tools:context=".MainActivity">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        app:contentPadding="10dp">

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

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@mipmap/ic_launcher" />

            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>
 

 

 

 

결과