일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- coroutinescope
- app-distribution
- monotone stack
- cancellationException
- Algorithm
- conflate
- Product Flavor
- coroutine
- TOSS 과제
- Kotlin
- java
- coroutinecontext
- hotStream
- 백준
- google play console
- ShapeableImageView
- Advanced LCA
- Next Challenge
- collectLatest
- 백준2309
- Android
- withContext
- KAKAO
- Flow
- flowon
- ServerDrivenUI
- 릴리즈 키해시
- coldStream
- SDUI
- 안드로이드
Archives
- Today
- Total
루피도 코딩한다
[Android] ShapableImageView radius설정하기 본문
진행중인 프로젝트에서 ImageView의 radius를 6dp 설정해야했다.
해당 프로젝트에서는 'Glide'를 활용하여 이미지를 표시해 주었다.
url을 활용한 이미지는 radius가 정상적으로 적용이 되었으나,
placeHolder에 넣어준 dummy img는 radius가 적용이 안되었다는 디자인 QA가 들어왔다..!
Before | After |
---|---|
![]() |
![]() |
기존에 glide를 활용한 코드는 아래와 같다.
@BindingAdapter("app:ogImage")
fun ImageView.setOgImage(url: String?) {
Glide.with(context)
.load(url)
.transform(CenterCrop(), RoundedCorners(px(6)))
.placeholder(R.drawable.img_contents_dummy_3)
.into(this)
}
이를 해결하기위해 ShapableImageView를 활용한 다른 방법을 적용해 보도록 하자.
1. styles.xml 추가
[res>values>styles.xml] 위치의 styles.xml 파일을 열고 아래 코드를 추가해준다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
...
<style name="roundedImageView6dp" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">6dp</item>
</style>
</resources>
2. (XML) ShapeableImageView 설정
1️⃣ 기존에 사용하던 ImaveView를 ShapeableImageView로 변경해주고
2️⃣ shapeAppearance를 아래와 같이 추가해준다.
<com.google.android.material.imageview.ShapeableImageView
...
app:ogImage="@{viewModel.ogData.ogImage}"
app:shapeAppearance="@style/roundedImageView6dp" />
app:ogImage는 첫번째 코드블락의 glide 코드를 그대로 사용하되, transform()부분을 지워주었다.
왜냐하면, 1번에서 추가한 roundedImageView6dp style을 적용해주었기 때문이다!
끝.
'Android' 카테고리의 다른 글
Github Action을 통해 Firebase App Distribution에 자동으로 Android 앱 배포하는 방법 (+ Slack에 노티까지!?) (2) | 2023.08.06 |
---|---|
[Android] Product Flavor 사용환경에서 Crashlytics 적용하기 (feat. slack 알림 연동) (2) | 2023.06.01 |
앱을 출시를 했는데요, 출시를 못했습니다 (2편/ Kakao Login) (4) | 2022.10.06 |
앱을 출시를 했는데요, 출시를 못했습니다 (1편/ Leakcanary) (7) | 2022.10.04 |
[Play Store] AAB(Android App Bundle)로 앱 업데이트하는 법 (0) | 2022.05.09 |
Comments