Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ItemTouchHelper滚动不';t在水平滚动视图中嵌套的recyclerView中工作_Android_Android Layout_User Interface_Kotlin_Androidx - Fatal编程技术网

Android ItemTouchHelper滚动不';t在水平滚动视图中嵌套的recyclerView中工作

Android ItemTouchHelper滚动不';t在水平滚动视图中嵌套的recyclerView中工作,android,android-layout,user-interface,kotlin,androidx,Android,Android Layout,User Interface,Kotlin,Androidx,我有一个水平的recyclerView,在它自己的片段中以线性布局。片段的占位符包装在水平滚动视图中。当我添加片段时,recyclerview nestedScroll设置为false,HorizontalScrollView控制滚动精细 但是,我现在已经在recyclerview上实现了ItemTouchHelper.Callback,以便能够对单元格进行重新排序。但是,当我将单元格移出屏幕时,它不会随之滚动。我尝试过更改nestedScroll和fixedSize,但没有任何效果 我不能使用

我有一个水平的recyclerView,在它自己的片段中以线性布局。片段的占位符包装在水平滚动视图中。当我添加片段时,recyclerview nestedScroll设置为false,HorizontalScrollView控制滚动精细

但是,我现在已经在recyclerview上实现了ItemTouchHelper.Callback,以便能够对单元格进行重新排序。但是,当我将单元格移出屏幕时,它不会随之滚动。我尝试过更改nestedScroll和fixedSize,但没有任何效果

我不能使用NestedScrollView,因为recyclerView是水平的,对吗

有什么建议吗

主xml

        <HorizontalScrollView
            android:id="@+id/timeline_horizontal_scroll_view"
            style="@style/timeline_horizontal_scroll_view_style">

            <FrameLayout
                android:id="@+id/media_scrub_placeholder"
                style="@style/media_scrub_placeholder_style" />
        </HorizontalScrollView>

片段xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/timeline_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>

在我的片段中,我可以用这个来解决这个问题

reorderTimelineRecyclerView.layoutManager = LinearLayoutManager(context!!, LinearLayoutManager.HORIZONTAL, false)
reorderTimelineRecyclerView.isNestedScrollingEnabled = true
broadcastScrollState(true, context!!)
val callback = SimpleItemTouchHelperCallback(adapter, context!!, listOfLocalAssets.size)
val touchHelper = ItemTouchHelper(callback)
touchHelper.attachToRecyclerView(reorderTimelineRecyclerView)
broadcastScrollState更新处于重新排序状态时要启用的回收器视图的滚动,并在之后将其关闭。因此,当用户长按时,它使用rcecyclerview的滚动,但当用户不长按时,它使用水平滚动视图的滚动。希望这对别人有帮助

编辑

fun broadcastScrollState(scrollState: Boolean, context: Context) {
    val intent = Intent("scroll-state-event")
    intent.putExtra("scroll-state", scrollState)
    LocalBroadcastManager.getInstance(context!!).sendBroadcast(intent)
}
然后在我的recycerlview片段中,我观察互联网并切换scrollview的滚动状态

private val scrollReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        updateScrollState(intent!!.getBooleanExtra("scroll-state", false))
    }
}

private fun updateScrollState(scrollState: Boolean) {
    timeline_horizontal_scroll_view.isEnabled = !scrollState
}

我在片段中用这个解决了这个问题

reorderTimelineRecyclerView.layoutManager = LinearLayoutManager(context!!, LinearLayoutManager.HORIZONTAL, false)
reorderTimelineRecyclerView.isNestedScrollingEnabled = true
broadcastScrollState(true, context!!)
val callback = SimpleItemTouchHelperCallback(adapter, context!!, listOfLocalAssets.size)
val touchHelper = ItemTouchHelper(callback)
touchHelper.attachToRecyclerView(reorderTimelineRecyclerView)
broadcastScrollState更新处于重新排序状态时要启用的回收器视图的滚动,并在之后将其关闭。因此,当用户长按时,它使用rcecyclerview的滚动,但当用户不长按时,它使用水平滚动视图的滚动。希望这对别人有帮助

编辑

fun broadcastScrollState(scrollState: Boolean, context: Context) {
    val intent = Intent("scroll-state-event")
    intent.putExtra("scroll-state", scrollState)
    LocalBroadcastManager.getInstance(context!!).sendBroadcast(intent)
}
然后在我的recycerlview片段中,我观察互联网并切换scrollview的滚动状态

private val scrollReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        updateScrollState(intent!!.getBooleanExtra("scroll-state", false))
    }
}

private fun updateScrollState(scrollState: Boolean) {
    timeline_horizontal_scroll_view.isEnabled = !scrollState
}

你能分享你的broadcastScrollState()方法吗?你能分享你的broadcastScrollState()方法吗?