我想了解为什么我似乎无法在 LinearLayoutManager 上使用 scrollToPositionWithOffset 方法?请看图片了解我的意思:
一点背景:
图像中的第一行(带有scrollToPosition
)是滚动 RecyclerView 以使位置(在本例中为 50)可见- 这通常意味着所选位置显示在可见 RecyclerView 的底部(其中位置 50 在 ' 之后首先变为可见)滚动')。而我想始终将其显示在顶部。从我的研究来看,一些解决方案似乎是使用这种scrollToPositionWithOffset
方法(Scroll RecyclerView to show selected item on top)
有趣的是,我能够通过自定义 LinearLayoutManager 的 SmoothScroller 来实现我想要的,但是我的数据集很大,所以“平滑滚动”的速度是一个问题,而且我似乎无法在不引起其他问题的情况下提高足够的速度。
简而言之,我希望 scrollToPositionWithOffset 能帮我解决问题。但是,我不知道如何访问该方法。
您能帮我理解为什么我无法在应用程序的 onCreate 中运行SoundManager.initialize(this)行吗?
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SoundManager.initialize(this)
}
}
Run Code Online (Sandbox Code Playgroud)
从
class SoundManager {
var soundPool: SoundPool
var c3 = 0
init {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
soundPool = SoundPool.Builder().setMaxStreams(13).build()
} else {
soundPool = SoundPool(13, AudioManager.STREAM_MUSIC, 5)
}
}
fun loadSound(context: Context) {
c3 = soundPool.load(context, R.raw.c3, 1)
}
fun playSound() {
soundPool.play(c3, 1.0f, 1.0f, 0, 0, 1.0f)
}
companion object {
private var singleton: SoundManager? = null
fun initialize(context: …
Run Code Online (Sandbox Code Playgroud)