상세 컨텐츠

본문 제목

[안드로이드 코틀린] 간단한 RecyclerView 만드는 방법 part1 - 데이터 & 화면

안드로이드

by aries574 2022. 5. 31. 13:59

본문


이번 시간에는 코틀린(Kotlin)으로 RecyclerView 리스트 만드는 방법

첫 번째 시간으로 데이터 담을 클래스와 화면을 만들어 보겠습니다. 


목차

1. 데이터 클래스 만들기
2. 아이템 화면 만들기 Item.kt
3. 메인 화면 구성 activity_main.xml


1. 데이터 클래스 만들기

  - 설명 - 

 데이터 담기 위한 클래스 

data class Item(

    //데이터 담기 위한 클래스
    var imageResource: Int,
    var text1: String
)


2. 아이템 화면 만들기 Item.kt

 - 설명 -

 1. 이미지를 보여줄 ImageView

 2. 내용을 보여줄 TextView

 3. 아이콘 res -> drawable

ic_call.xml
0.00MB
ic_boy.xml
0.00MB
ic_android.xml
0.00MB

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="4dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_android" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/imageView"
            android:text="내용"
            android:textSize="18sp"
            android:textStyle="bold"/>
    </RelativeLayout>

</androidx.cardview.widget.CardView>

 


3. 메인 화면 구성 activity_main.xml

 - 설명 - 

 1. 리스트를 보여줄 RecyclerView

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:padding="4dp" />
</RelativeLayout>

2022.04.08 - [안드로이드] - [안드로이드] Tab Custom Animation part1 - 화면 구성

 

[안드로이드] Tab Custom Animation part1 - 화면 구성

이번 시간부터 TabLayout을 직접 만들어 애니메이션까지 넣어보는 방법을 알아보겠습니다. 이번 포스팅은 화면 구성을 해보겠습니다. 목차 1. 실행 화면 2. 테마 변경 3. 배경 색상 파일 만들기(drawab

aries574.tistory.com

2022.03.23 - [안드로이드] - [안드로이드] tic-tac-toe 보드게임 만드는 방법 part1 - 화면 구성

 

[안드로이드] tic-tac-toe 보드게임 만드는 방법 part1 - 화면구성

이번 시간에는 Tic Tac Toe라는 게임을 만들어 보겠습니다. 두 명이서 번갈아 가며 클릭을 하며 가로, 세로, 대각선 중 한 줄을 만들면 이기는 단순한 게임입니다. 이번에는 화면만 구성하겠습니다.

aries574.tistory.com

2022.03.02 - [안드로이드] - [안드로이드] SQLite RecyclerView 연락처 만드는 방법 part1 - 조회

 

[안드로이드] SQLite RecyclerView 연락처 만드는 방법 part1 - 조회

앞으로 SQLite, RecyclerView를 통해서 연락처 만드는 방법을 알아보겠습니다. 내용이 많다 보니 조회, 등록, 수정, 삭제 별로 나눠 올리겠습니다. 이번에는 조회 부분입니다. 목차 1. 실행 화면 2. 연락

aries574.tistory.com

 

반응형

관련글 더보기

댓글 영역