Код: Выделить всё
private fun addCustomViewToWindow() {
windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
customView = CustomViewToAttachToRoot(this, this)
val layoutParams = WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
android.graphics.PixelFormat.TRANSLUCENT
).apply {
gravity = Gravity.BOTTOM
}
val customComposeView = ComposeView(this).apply {
setContent {
ChangingHeightComposable()
}
}
customView.addView(customComposeView)
windowManager.addView(customView, layoutParams)
}
< /code>
Custom Framelayout < /code>: < /h3>
class CustomViewToAttachToRoot(
context: Context,
private val lifecycleOwner: LifecycleOwner
) : FrameLayout(context) {
init {
setBackgroundColor(resources.getColor(R.color.purple_500))
setViewTreeLifecycleOwner(lifecycleOwner)
if (lifecycleOwner is SavedStateRegistryOwner) {
setViewTreeSavedStateRegistryOwner(lifecycleOwner)
}
}
}
< /code>
ComposableКод: Выделить всё
@Composable
fun ChangingHeightComposable() {
val infiniteTransition = rememberInfiniteTransition(label = "heightTransition")
val animatedHeight by infiniteTransition.animateValue(
initialValue = 200.dp,
targetValue = 100.dp,
typeConverter = Dp.VectorConverter,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1000),
repeatMode = RepeatMode.Reverse
),
label = "animatedHeight"
)
Box(
modifier = Modifier
.fillMaxWidth()
.height(animatedHeight)
.background(Color.Cyan)
)
}
< /code>
💡 Примечания о мерцании: < /p>
Обычно происходит мерцание, потому что Windowmanager < /code> пытается решить вид каждую кадр при динамике. Измерение/макет Подробнее здесь: https://stackoverflow.com/questions/797 ... ap-content