Forum für diejenigen, die für Android programmieren
Anonymous
Klicken Sie zuerst auf Lazylist, funktioniert nicht nur an zweiter Stelle
Post
by Anonymous » 15 Feb 2025, 08:09
Ich habe einen Bildschirm mit komponierbarer Funktion mit Lazyrow im Inneren. . Und - Erster Klick fängt nicht Onclick Block ein. Was mache ich falsch? < /P>
Code: Select all
@Composable
fun RoommsScreenPart(
modifier: Modifier = Modifier,
uiState: State
) {
val state = rememberLazyListState()
var canScrolling by remember { mutableStateOf(true) }
val density = LocalDensity.current
Box(modifier = modifier) {
if (uiState.items.isNotEmpty()) {
Column {
Text(
text = "Title",
style = AppTheme.typography.title2,
color = AppTheme.colorScheme.onSurface
)
LazyRow(
modifier = Modifier.clickable { canScrolling = false },
state = state,
userScrollEnabled = true,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Dp8)
) {
items(
count = Int.MAX_VALUE,
itemContent = {
val index = it % uiState.items.size
Roomm(uiState.items[index])
}
)
}
}
}
LaunchedEffect(Unit) {
snapshotFlow { canScrolling }
.collect {
if (it) {
while (true) {
val needToScrollItems =
uiState.items.size - state.layoutInfo.visibleItemsInfo.size + 1
state.animateScrollBy(
value = needToScrollItems * with(density) { Dp40.toPx() },
animationSpec = tween(
durationMillis = 4000 * needToScrollItems,
easing = LinearEasing
)
)
delay(100)
}
}
}
}
LaunchedEffect(Unit) {
snapshotFlow { canScrolling }
.collect {
if (!it) {
delay(5000)
canScrolling = true
}
}
}
}
}
< /code>
Lazylistelement < /p>
@Composable
private fun Roomm(item: Item) {
Box(
modifier = Modifier
.fillMaxHeight()
.aspectRatio(1f)
.clip(RoundedCornerShape(Dp12))
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(item.photoLink)
.crossfade(true)
.error(R.drawable.room_large)
.build(),
contentScale = ContentScale.Crop,
contentDescription = null,
modifier = Modifier.fillMaxSize(),
)
}
}
1739603378
Anonymous
Ich habe einen Bildschirm mit komponierbarer Funktion mit Lazyrow im Inneren. . Und - Erster Klick fängt nicht Onclick Block ein. Was mache ich falsch? < /P> [code]@Composable fun RoommsScreenPart( modifier: Modifier = Modifier, uiState: State ) { val state = rememberLazyListState() var canScrolling by remember { mutableStateOf(true) } val density = LocalDensity.current Box(modifier = modifier) { if (uiState.items.isNotEmpty()) { Column { Text( text = "Title", style = AppTheme.typography.title2, color = AppTheme.colorScheme.onSurface ) LazyRow( modifier = Modifier.clickable { canScrolling = false }, state = state, userScrollEnabled = true, verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(Dp8) ) { items( count = Int.MAX_VALUE, itemContent = { val index = it % uiState.items.size Roomm(uiState.items[index]) } ) } } } LaunchedEffect(Unit) { snapshotFlow { canScrolling } .collect { if (it) { while (true) { val needToScrollItems = uiState.items.size - state.layoutInfo.visibleItemsInfo.size + 1 state.animateScrollBy( value = needToScrollItems * with(density) { Dp40.toPx() }, animationSpec = tween( durationMillis = 4000 * needToScrollItems, easing = LinearEasing ) ) delay(100) } } } } LaunchedEffect(Unit) { snapshotFlow { canScrolling } .collect { if (!it) { delay(5000) canScrolling = true } } } } } < /code> Lazylistelement < /p> @Composable private fun Roomm(item: Item) { Box( modifier = Modifier .fillMaxHeight() .aspectRatio(1f) .clip(RoundedCornerShape(Dp12)) ) { AsyncImage( model = ImageRequest.Builder(LocalContext.current) .data(item.photoLink) .crossfade(true) .error(R.drawable.room_large) .build(), contentScale = ContentScale.Crop, contentDescription = null, modifier = Modifier.fillMaxSize(), ) } } [/code]
0 Replies
0 Views
Last post by Anonymous
12 Jul 2025, 23:25
0 Replies
3 Views
Last post by Anonymous
12 Jul 2025, 23:25
0 Replies
7 Views
Last post by Anonymous
15 Feb 2025, 08:15
0 Replies
12 Views
Last post by Anonymous
13 Apr 2025, 11:33
0 Replies
15 Views
Last post by Anonymous
14 Apr 2025, 20:16