小编Joh*_*tto的帖子

Kotlin/RecyclerView:scrollToPositionWithOffset 没有出现

我想了解为什么我似乎无法在 LinearLayoutManager 上使用 scrollToPositionWithOffset 方法?请看图片了解我的意思:

未找到 scrollToPositionWithOffset !

一点背景:

图像中的第一行(带有scrollToPosition)是滚动 RecyclerView 以使位置(在本例中为 50)可见- 这通常意味着所选位置显示在可见 RecyclerView 的底部(其中位置 50 在 ' 之后首先变为可见)滚动')。而我想始终将其显示在顶部。从我的研究来看,一些解决方案似乎是使用这种scrollToPositionWithOffset方法(Scroll RecyclerView to show selected item on top

有趣的是,我能够通过自定义 LinearLayoutManager 的 SmoothScroller 来实现我想要的,但是我的数据集很大,所以“平滑滚动”的速度是一个问题,而且我似乎无法在不引起其他问题的情况下提高足够的速度。

简而言之,我希望 scrollToPositionWithOffset 能帮我解决问题。但是,我不知道如何访问该方法。

android kotlin

4
推荐指数
1
解决办法
1578
查看次数

代码未在应用程序的 onCreate 上执行 - Kotlin/Android

您能帮我理解为什么我无法在应用程序的 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)

android kotlin

2
推荐指数
1
解决办法
723
查看次数

标签 统计

android ×2

kotlin ×2