이미지를 둥글게 만드는 경우는 정말 정말 많다! 필수 기능 중 하나라고 봐도 무방할 정도다. 저렇게 둥근 이미지들이 잔뜩 들어갈 때는 어떻게 만들면 좋을까?
1️⃣ res/drawble 폴더에 background 생성
이렇게 xml 파일을 생성하여 아래코드처럼 작성하면 된다. 두 가지 방법 모두 잘 작동한다.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" />
android:shape="oval" props 값을 주게 되면 손쉽게 원형을 생성할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50dp" />
</shape>
shape 태그 안에 <corners android:radius="50dp" /> 태그를 줌으로 인해서 View의 radius 값을 줄 수 있는데 이때에는 내가 radius를 주려고 하는 원래 View와 dp값을 잘 맞춰주어야한다. 이 점을 유의하자.
2️⃣ layout 폴더 내의 xml파일에서 background 적용하기
이렇게 background옵션에 방금 drawble폴더에서 생성한 xml파일을 적용해주고 clipToOutline="true" 옵션을 주면 끝난다. 아래는 코드 전문이다.
<ImageView
android:id="@+id/home_imageView1"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginEnd="16dp"
android:scaleType="centerCrop"
android:background="@drawable/bg_circle"
android:src="@drawable/home_feed_profile1"
android:clipToOutline="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
이렇게까지 비효율적으로... 가공해야 할 이유가 뭘까...?
이런 편의성은 언제 개선되는걸까...??
'Android' 카테고리의 다른 글
Android의 4대 구성요소 알아보기 (0) | 2024.08.14 |
---|---|
Android에서 Fragment와 TabLayout, 그리고 RecyclerView 적용하기 (0) | 2024.08.05 |
Android에서 Lottie Animation 적용하기 (0) | 2024.07.04 |
Android란? (0) | 2024.06.21 |
HTML과 XML 의 차이 (2) | 2024.05.30 |