gpt4 book ai didi

Android smoothScrollTo 不流畅

转载 作者:太空宇宙 更新时间:2023-11-03 10:19:16 28 4
gpt4 key购买 nike

我正在尝试滚动到 ScrollView 中的给定布局。我的 XML 基本上由实现各种 RelativeLayout 的 ScrollView 组成,我想以编程方式滚动到给定的一个。

我的 Activity 的 onCreate 方法中有以下代码:

// Defining my view
sv = (ScrollView)findViewById(R.id.reward_scroll_view);

// Get Layout's id from intent
Bundle extras = getIntent().getExtras();
if (extras != null) {
idToScroll = extras.getInt("uiToScroll");
sv.post(new Runnable() {
public void run() {

// Scroll to the passed element
RelativeLayout layout = (RelativeLayout) findViewById(idToScroll);
sv.smoothScrollTo(0, layout.getTop());
}
});
}

给定 anchor 的“自动滚动”正在运行,但没有“平滑”效果,只是布局的原始滚动。我错过了什么?

最佳答案

您正在覆盖 post View 方法。

ScrollView 在 UI Thread 或 Post 中不能流畅地工作

Look at this question

关于Android smoothScrollTo 不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27482351/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com