You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jetpack Compose TabRow搭配Accompanist WebView时出现闪烁问题

Jetpack Compose TabBar 搭配 WebView 出现闪烁/重叠问题

在Jetpack Compose中实现TabBar,并使用WebView作为分页内容时,会出现闪烁或视图重叠的现象。将WebView替换为其他组件(比如Box包裹Text)后,该问题消失。从现象来看,WebView会短暂超出自身布局边界。

更新说明

我排查了重组相关问题,还专门制作了一个简易测试项目,但未发现TabBar需要重组的触发原因。给TabBar设置固定高度后,Tab内的文本始终能保持在TabBar范围内,不会再出现重叠。

以下是测试项目中的标准实现代码:

@Composable
private fun MyTabRow(
    pagerState: PagerState,
    coroutineScope: CoroutineScope,
) {
    TabRow(
        selectedTabIndex = pagerState.currentPage,
        indicator = { tabPositions ->
            TabRowDefaults.Indicator(
                Modifier.pagerTabIndicatorOffset(pagerState, tabPositions),
                color = MaterialTheme.colors.secondary
            )
        },
    ) {
        tabRowItems.forEachIndexed { index, item ->
            Tab(
                selected = pagerState.currentPage == index,
                onClick = { coroutineScope.launch { pagerState.animateScrollToPage(index) } },
                icon = {
                    Icon(imageVector = item.icon, contentDescription = "")
                },
                text = {
                    Text(
                        text = item.title,
                        maxLines = 2,
                        overflow = TextOverflow.Ellipsis,
                    )
                },
            )
        }
    }
    HorizontalPager(
        count = tabRowItems.size,
        state = pagerState,
    ) {
        ShowWebView("http://google.com")
    }
}

内容的提问来源于stack exchange,提问作者MNielsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 22:25:30