android studio Recycle View 생성하기 -1
1. 프로젝트를 생성합니다.
생성방법은 해당 글을 참고해 주시기 바랍니다. : android studio 프로젝트 생성하기
2. 사용할 이미지를 drawable에 추가한다.
CardView안에 이미지를 삽입해서 각각의 Recycle View안에 추가할수 있다. 이를 위해서 해당 xml파일을 수정해야한다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content">
<!-- 해당 recycleview_ele.xml은 Recycle View에 데이터를 표현하기 위한 템플릿입니다. -->
<!-- 하나의 recycleview_ele.xml은 하나의 데이터를 표현합니다.-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="100dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 게임 View를 배치한다. -->
<ImageView
android:id="@+id/gameImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/portal2_logo2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- 게임 타이틀을 표시하는 TextView를 배치한다.-->
<TextView
android:id="@+id/gameTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="16dp"
android:text="TextView"
android:textSize="20dp"
app:layout_constraintStart_toEndOf="@+id/gameImageView"
app:layout_constraintTop_toTopOf="parent" />
<!-- 해당 게임 타이틀의 내용을 설명하는 TextView를 배치한다.-->
<TextView
android:id="@+id/gemeDetailsView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginBottom="22dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/gameImageView"
app:layout_constraintTop_toBottomOf="@+id/gameTitleView"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
이제 해당 CardView가 완료됬기 때문에 해당 코드를 저장한다.
main activity에 RecycleView를 추가한다. 다음글에서 해당 RecycleView에 어뎁터를 추가해서 실제적으로 동작이 되게 하겠다.
gitHubLink : https://github.com/Alex-Choi0/android_recycleView_Excercise1.git
다음글 : android studio Recycle View 적용하기 -2
댓글
댓글 쓰기