96SEO 2026-08-04 07:07 6
在 ChatGPT 这类对话页里一次回答通常不是一次性插入完整列表,而是同一条回答内容持续追加、同一个列表项不断变高。
这篇文章主要目标是:当列表处于自动贴底状态时最终一项每次内容更新、重组、高度变化,都能自然跟随到底部;当使用者进入自由滑动状态时最终一项继续更新也不应该把当前位置重新拉回底部。

这篇文章记录了实现这一目标的迭代过程:先从正向视觉的自动滚动开始,再尝试 LazyColumn 反向视觉。接下来用 snapshotFlow + scrollBy 做布局后的补偿,最终演进到一个基于 LazyLayout 的双锚点列表 AnchorLazyColumn。
普通列表通常以“顶部”为视觉起点:新数据插入后只要保持当前首个可见项不变,使用者就不会感觉跳动。但 ChatGPT 类流式回答列表的关键点在最终一项:
这类需求很容易被误解成“每次数据变化都滚到底部”。真正要解决的是高度变化和滚动跟随的时序: "最终一项先变高、下一帧再滚动" ——如果两者在不同帧完成,就会出现追赶感或跳动。
This iteration can be split into four solutions:
The first three solutions all build on LazyColumn,differing only in scrolling strategy and visual direction. The fourth solution treats “anchor” as part of list’s own layout contract.
The most direct implementation is to keep natural data order,list placed forward。n scroll to bottom when data changes:
val listState = rememberAutoScrollListState(
trigger = outputs.size to isStreaming,)
LazyColumn {
items { index ->
OutputItem
}
if ) {
item {
OutputItem
}
}
}
The helper rememberAutoScrollListState
@Composable
fun rememberAutoScrollListState(
listState: LazyListState = rememberLazyListState,enabled: Boolean = true,trigger: Any?): LazyListState {
var autoScroll = enabled
val isAtBottom by remember {
derivedStateOf { listState.isFullyScrolledToBottom }
}
LaunchedEffect {
if {
autoScroll = true
}
}
LaunchedEffect {
if {
listState.scrollToBottom
}
}
return listState
}
The scrolling logic relies on measuring layout info and possibly animating:
suspend fun LazyListState.scrollToBottom {
val lastIdx = layoutInfo.totalItemsCount - 1
if return
val delta = calculateBottomScrollDelta)
if {
animateScrollToItem
return
}
if {
animateScrollToItem
}
}
This approach is simple but problematic: last item recomposes and grows before list scrolls down again. Height change and scrolling happen in separate frames,producing a jumpy feel.
The second solution uses reverseLayout=true so that items appear at bottom visually:
LazyColumn(
state = listState,reverseLayout = true,){
if ){
item{
OutputItem
}
}
for{
val sourceIndex=outputs.lastIndex - offset
item{
OutputItem
}
}
}
This mitigates jumpy behavior during streaming growth but still suffers when user is freely scrolling: as long as last item remains visible,its height changes can still drag viewport downward.
The third approach returns to normal orientation but listens for height changes on last item instead of just triggering a scroll after each data change.
LazyColumn(
state=listState,modifier=Modifier
.stickToBottom(
listState=listState,enabled=followLatest,)
.autoScrollAware(
onUserInteracted={followLatest=false},onUserInteractionEnd={
followLatest=listState.isFullyScrolledToBottom
},)。){
items{index->
OutputItem
}
}
`autoScrollAware` detects user touch interactions to toggle auto‑scroll mode.
`stickToBottom` monitors last visible item's size after layout and adjusts `scrollBy` accordingly.
This reduces obvious jumps but still has a timing gap because height change happens before scroll adjustment.
缺陷不足
-
补偿时机天然偏晚 – layout finishes first n snapshotFlow reads new size – thus “height change → n scroll” sequence introduces small lag or chase effect under rapid updates or low frame rates.
-
Switch 娱乐ween “follow” and “lock” states isn’t a simple boolean – you risk re‑scrolling back to bottom every time you update data which steals user's position from history view.
-
Inertia/fling handling becomes tricky – custom drag handlers don’t propagate natural fling physics unless you use standard scrolling containers which don’t allow measurement‑time anchoring.
从新方案来看,双锚点 AnchorLazyColumn
-
User Pain Point #1: Your chat always jumps when new lines appear while you’re reading older messages – this hurts focus.
-
User Pain Point #2: You want instant follow‑bottom during typing but also want to pause that when exploring conversation history without being pulled back automatically.
The core idea: move anchoring into measurement rar than post‑layout compensation.
kotlin
enum class AnchorMode{
Bottom,// viewport locked at bottom – ideal for streaming output.
Locked // viewport stays where user left it – ideal for browsing history.
}
@Composable
fun rememberAnchorLazyListState: AnchorLazyListState =
remember{ AnchorLazyListState }
val state=rememberAnchorLazyListState
AnchorLazyColumn(
modifier=Modifier.fillMaxSize,state=state,){
items{
OutputItem
}
if){
unstableItem{
OutputItem
}
}
}
The key part lies in measureBottom & measureLocked functions inside AnchorLazyLayout. In Bottom mode each pass measures from end toward top until enough space fills viewport – any height increase immediately shifts placement within same frame so no separate scroll command needed. When user drags upward anchor switches to Locked mode recording current firstVisibleIndex & offset. Subsequent updates do not affect that position unless user returns to bottom again – n automatic switch back occurs.
迭代流程
-
. 保留 LazyColumn → 用 animateContentSize,snapshotFlow+scrollBy 补偿高度 → 能解决部分追尾问题,但仍有帧间差距。• 第一步先验证“高度变化后要跟随到底部”是正确方向。话说回来,• 后置补偿始终晚于布局 → 可见追赶感。按理说,• 原因是“底部锚定太晚”。必须在同一次 measure pass 内确定位置。• 改为自定义测量并从末尾往前测量即实现 Bottom 锚定。• 当使用者滑动 → 切到 Locked 并记录首个可见索引与裁剪偏移。• 回到底部则恢复 Bottom 再触发 flush。
快速搭建
kts
internal fun MeasureResult.measureImpl{…}
// see full source above
请问还有什么想进一步改进的吗?
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback