android recyclerview.scrollto или scrollto позиция не работает во фрагменте - PullRequest
0 голосов
/ 11 апреля 2020

привет, у меня есть этот макет с видом переработчика

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SuraDetails.SuraDetails">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary">
    <EditText
            android:id="@+id/search_edittext_details"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="false"
            android:background="@drawable/searchfieldback"
            android:layout_margin="7dp"
            android:padding="5dp"
    />
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/sura_details_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView>

фрагмент

вот код фрагмента

{
    adapter = SuraDetailsAdapter(sura.verses!!, context!!, sura)
    recyclerView!!.layoutManager=layoutManager
    recyclerView!!.adapter=adapter
    if (pos!=null){
        recyclerView!!.scrollToPosition(pos)
    }
    /*recyclerView!!.adapter=adapter
    recyclerView!!.layoutManager=layoutManager*/
    // recyclerView!!.scrollToPosition()
    return view
}

}

все работает хорошо

но! recyclerView!!.scrollToPosition()

не работает, я читаю различные вопросы, связанные с этой топикой c здесь, в стеке, но ничего не помогает

РЕДАКТИРОВАТЬ

Я просмотрел свою предыдущую ветку и обнаружил, что там все работает хорошо, но xml проще

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SuraDetails.SuraDetails">
<TextView
        android:id="@+id/sura_details_suraname_english"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
        android:id="@+id/sura_details_suraname_russian"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center"/>
<TextView
        android:id="@+id/sura_details_bismi_arabik"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center"/>
<TextView
        android:id="@+id/sura_details_bismi_ukr"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center"/>
<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/sura_details_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

может быть, проблема кроется здесь

Обновление

я думаю, я нашел, что нашел источник проблемы, мой фрагмент обернут Вложенный вид прокрутки, поэтому у меня есть вложенный вид прокрутки и в нем окно просмотра recycler view in nested scroll view

Ответы [ 2 ]

0 голосов
/ 11 апреля 2020

Можете ли вы попробовать это:

recyclerView.post {
   recyclerView.scrollToPosition(pos)
}

или

recyclerView.postDelayed(Runnable {
   recyclerView.scrollToPosition(pos)
},2000)
0 голосов
/ 11 апреля 2020

Вы пробовали это:

recyclerView.smoothScrollToPosition(position)

или

(recyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(position, 0)

Надеюсь, эта помощь!

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