@Composable
fun DrawScrollableView(modifier: Modifier,content: @Composable () -> Unit) {
AndroidView(
modifier = modifier,
factory = {
val scrollView = ScrollView(it).apply {
scrollBarSize = 4
isVerticalFadingEdgeEnabled = true
isScrollbarFadingEnabled = false
}
val layout = LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
scrollView.layoutParams = layout
scrollView.addView(ComposeView(it).apply {
setContent {
content()
}
})
val linearLayout = LinearLayout(it)
linearLayout.orientation = LinearLayout.VERTICAL
linearLayout.layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)
linearLayout.addView(scrollView)
linearLayout
}
)
}
@Composable
fun MY(){
DrawScrollableView(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(),
content = {
Column {
repeat(20) {
Row {
Text(text = "Jetpack scroll view")
Spacer(modifier = Modifier.size(20.dp))
Image(painter = painterResource(id = R.drawable.a2), contentDescription = null)
}
}
}
}
)
}