исправить высоту полосы прокрутки во вложенном реселлере - PullRequest
0 голосов
/ 11 июля 2019

У меня есть горизонтальная Recyclerview внутри другой горизонтальной Recyclerview. Теперь я хочу показать scrollbar. Но высота полосы прокрутки меняется при прокрутке. Я хочу иметь фиксированную высоту полосы прокрутки при прокрутке. Как я могу этого достичь? У меня есть кастом LinearLayoutManager. Но это не работает должным образом. Есть ли лучшее решение этой проблемы?

class CoolLayoutManager(context: Context,orientation: Int,
  reverseLayout: Boolean) : LinearLayoutManager(context,orientation,
    reverseLayout) {

  init {
    isSmoothScrollbarEnabled = true
  }

  override fun computeHorizontalScrollExtent(state: State): Int {
    val count = childCount
    return if (count > 0) {
      SMOOTH_VALUE * 3
    } else 0
  }

  override fun computeHorizontalScrollRange(state: State): Int {
    return Math.max((itemCount - 1) * SMOOTH_VALUE, 0)
  }

  override fun computeHorizontalScrollOffset(state: State): Int {
    val count = childCount

    if (count <= 0) {
      return 0
    }
    if (findLastCompletelyVisibleItemPosition() == itemCount - 1) {
      return Math.max((itemCount - 1) * SMOOTH_VALUE, 0)
    }

    val widthOfScreen: Int
    val firstPos = findFirstVisibleItemPosition()
    if (firstPos == RecyclerView.NO_POSITION) {
      return 0
    }
    val view = findViewByPosition(firstPos) ?: return 0
// Top of the view in pixels
    val top = getDecoratedTop(view)
    val width = getDecoratedMeasuredWidth(view)
    widthOfScreen = if (width <= 0) {
      0
    } else {
      Math.abs(SMOOTH_VALUE * top / width)
    }
    return if (widthOfScreen == 0 && firstPos > 0) {
      SMOOTH_VALUE * firstPos - 1
    } else SMOOTH_VALUE * firstPos + widthOfScreen
  }


  companion object {
    private const val SMOOTH_VALUE = 100
  }
}

Вот скриншот макета: enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...