개발/안드로이드
RoundedFrameLayout
kwony
2021. 3. 3. 13:26
디자이너와 협업하다보면 위 그림처럼 이미지의 꼭지점 부분에 radius를 넣어야하는 경우가 종종 생긴다. 아이콘으로 넣는 이미지의 경우에는 디자이너가 직접 아이콘의 radius를 먹일 수 있는데 뉴스피드처럼 외부에서 받아오는 이미지의 경우에는 매번 작업을 할 수 없어 코딩으로 처리해야한다. 이럴 경우 RoundedFrameLayout 라이브러리를 사용하면 쉽게 처리가 가능하다.
1. 라이브러리 설치
build.gradle에 추가해서 적용한다.
dependencies {
// RoundedFrameLayout
compile 'com.github.QuarkWorks:RoundedFrameLayout-Android:0.3.7'
}
2. 적용
RoundedFrameLayout은 이미지가 적용되는 ImageView의 부모로 설정한다. 뷰의 속성 값으로 cornerRadius가 있는데 이 값을 이용해서 얼마나 깎을 것인지 적용 할 수 있다. ImageView는 부모 레이아웃이 변경됐으므로 자동으로 적용되게된다.
<com.quarkworks.roundedframelayout.RoundedFrameLayout
android:id="@+id/layout_rounded_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cornerRadiusTopLeft="10dp"
app:cornerRadiusTopRight="10dp"
app:cornerRadiusBottomLeft="10dp"
app:cornerRadiusBottomRight="10dp">
<ImageView
android:id="@+id/layout_rounded_image_iv"
android:background="#0c000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
</com.quarkworks.roundedframelayout.RoundedFrameLayout>