[Android studio] ImageView 모서리 동그랗게

노유성·2023년 7월 3일
0
post-thumbnail

style_img.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:bottomLeftRadius="15dp"
        android:bottomRightRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />
</shape>

모서리를 동그랗게 하기 위한 xml 파일을 준비한다.

스타일 적용하기

 <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/example"
            android:scaleType="fitXY"
            android:background="@drawable/style_img"/>

android:scaleType="fitXY"는 이미지 뷰 크기에 이미지가 꽉차도록 하는 속성이다. 해당 속성과 함께 background 속성에 스타일을 지정한다.

MainActivity.java

Image =.findViewById(R.id.openImageView);

Image.setClipToOutline(true);

마지막으로 imageView를 잡아준 다음, 위와 같은 코드를 기재한다.

그럼 위와 같이 둥근 이미지가 만들어진다.

profile
풀스택개발자가되고싶습니다:)

0개의 댓글