recyclerview를 이용해 gridview를 동적으로 생성하였는데
요소들이 왼쪽 정렬이 되었다. 가운데 정렬을 하기 위해 gravity를 center로 하면 해결이 될 줄 알았으나 실패..
이것저것 해보다가 결국 찾았다.
width를 match parent로 두어 최대로 하고
margin을 주어 여백을 만들었다.
그리고 하위 요소에 adjustviewbounts를 true로 주어서 가로 세로 비율을 동일하게 주었다.
코드
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardCornerRadius="15dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.cardview.widget.CardView>
결과

'안드로이드 > KOTLIN' 카테고리의 다른 글
[Jitpack] 사용하기 (0) | 2023.01.17 |
---|---|
[ANDRIOID - KOTLIN] runOnUiThread - 작업 스레드에서 UI 업데이트 요청하기 (0) | 2022.09.30 |
Retrofit2 (0) | 2022.07.20 |
[KOTLIN] - PendingIntent (0) | 2022.07.16 |
Room 사용법 [kotlin] - android local database (0) | 2022.07.12 |