一方、BitmapDrawable では elevation を指定しても影がでません。(2番目)

val provider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
val radius = 32 * resources.displayMetrics.density
outline.setRoundRect(0, 0, view.width, view.height, radius)
}
}
findViewById<View>(R.id.frameLayout4).apply {
outlineProvider = provider
clipToOutline = true
}
ViewOutlineProvider を使わずに、ShapeDrawable と BitmapShader でも影がでるようにすることができます。(2番目)
val r = 16 * resources.displayMetrics.density
val shapeDrawable = ShapeDrawable(
RoundRectShape(floatArrayOf(r, r, r, r, r, r, r, r), null, null)
)
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.image_round)
shapeDrawable.shaderFactory = object: ShapeDrawable.ShaderFactory() {
override fun resize(width: Int, height: Int): Shader {
val bmp = bitmap.scale(width, height, false)
return BitmapShader(bmp, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
}
}
findViewById<View>(R.id.frameLayout2).background = shapeDrawable
0 件のコメント:
コメントを投稿