简体   繁体   English

LazyColumn 项目相互叠加

[英]LazyColumn items draw on top of each other

I was using Jetpack Compose version 1.0.0-alpha01 and LazyColumnFor to display some items in a list.我使用 Jetpack Compose 版本 1.0.0-alpha01 和 LazyColumnFor 在列表中显示一些项目。 After updating to 1.0.0-beta06 I noticed that LazyColumnFor had been deprecated in favor of LazyColumn.更新到 1.0.0-beta06 后,我注意到 LazyColumnFor 已被弃用,取而代之的是 LazyColumn。 After migrating however, the items in the list draw on top of each other instead of being listed vertically with some spacing in between.然而,在迁移之后,列表中的项目会相互叠加,而不是垂直列出,中间有一些间距。

What's odd here is that the Preview renders the items as expected, while the app installed on the device(s) does not.奇怪的是,预览会按预期呈现项目,而安装在设备上的应用程序却没有。

Here's the activity:这是活动:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val textStyle = TextStyle(color = Color.White, fontSize = 16.sp)
            val boldStyle = textStyle.merge(TextStyle(fontWeight = FontWeight.Bold))
            ComposeListTestTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    LazyColumn(modifier = Modifier.fillMaxHeight()) {
                        items(listOf("Row1", "Row2")) { day ->
                            Text(
                                text = day,
                                style = boldStyle,
                                modifier = Modifier.padding(top = 8.dp),
                                color = Color.Green
                            )
                        }
                    }
                }
            }
        }
    }
}

在此处输入图像描述

And here's the preview:这是预览:

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
    val textStyle = TextStyle(color = Color.White, fontSize = 16.sp)
    val boldStyle = textStyle.merge(TextStyle(fontWeight = FontWeight.Bold))
    ComposeListTestTheme {
        Surface(
            modifier = Modifier.fillMaxSize(),
            color = MaterialTheme.colors.background
        ) {
            LazyColumn(modifier = Modifier.fillMaxHeight()) {
                items(listOf("Row1", "Row2")) { day ->
                    Text(
                        text = day,
                        style = boldStyle,
                        modifier = Modifier.padding(top = 8.dp),
                        color = Color.Green
                    )
                }
            }
        }
    }
}

在此处输入图像描述

Unfortunately I haven't been able to get the new layout inspector to work on any of my devices, or I suspect I could've seen some clues as to why this happens.不幸的是,我无法让新的布局检查器在我的任何设备上工作,或者我怀疑我可能已经看到了一些关于为什么会发生这种情况的线索。

ComposeListTestTheme: ComposeListTest主题:

@Composable
fun ComposeListTestTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable() () -> Unit
) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    MaterialTheme(
        colors = colors,
        typography = Typography,
        shapes = Shapes,
        content = content
    )
}

The issue happened because the app was not hardware accelerated.发生此问题是因为该应用程序未进行硬件加速。 This was fixed in https://issuetracker.google.com/issues/187853238 .这已在https://issuetracker.google.com/issues/187853238中修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM