반응형
android ImageView에 라운드 처리를 하기 위해서 res/drawable/ 에 background.xml을 만들어 적용하는 방법이 있지만, ImageView를 상속시킨 UIView를 직접 만들어 사용해도 된다.
package cloud.shoplive.sdk.ui
import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.graphics.RectF
import android.util.AttributeSet
import android.widget.ImageView
class CornerRoundedImageView: ImageView {
companion object {
const val RADIUS = 20.0f
}
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
constructor(context: Context?, attributeSet: AttributeSet?, defStyleAttr: Int?) : super(
context,
attributeSet,
defStyleAttr!!
)
override fun onDraw(canvas: Canvas?) {
val clipPath = Path()
val rect = RectF(0F, 0F, this.width.toFloat(), this.height.toFloat())
clipPath.addRoundRect(
rect, RADIUS, RADIUS, Path.Direction.CW
)
canvas?.clipPath(clipPath)
super.onDraw(canvas)
}
}
이미지가 bitmap이라면 아래처럼 bitmap을 직접 Round 처리하는 방법도 있다.
android 비트맵 라운드 처리 (Rounded Bitmap)
안드로이드에서 이미지 작업을 쉽게 할 수 있도록 제공되는 서드파티 라이브러리가 많이 있지만, 때로는 서드파티 라이브러리를 사용할 수 없어서 직접 핸들링을 해야 하는 경우가 있다. private
shary1012.tistory.com
반응형
'android' 카테고리의 다른 글
android ActionBar Menu Button 대문자를 소문자로 바꾸기 (0) | 2022.03.15 |
---|---|
android gradle dependencies clean (0) | 2022.03.04 |
android 비트맵 라운드 처리 (Rounded Bitmap) (0) | 2022.02.28 |
android ExoPlayer PlayerView Corner Rounded (0) | 2022.02.28 |
android ActionBar MenuItem uppercase issue (0) | 2022.02.28 |