Horizo ntalScrollView Android里面的RecyclerView

问题描述 投票:0回答:1

我在水平滚动视图中使用Recycler视图来显示如下的线程注释:

How1 How1Child1 How1Child2 How1Child2Child1 How1Child3 How2

等等

我用以下XML完成了这个:

<HorizontalScrollView
                android:id="@+id/horizontalScrollView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbarSize="2dp">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/commentRV"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_marginLeft="47dp"
                    android:minWidth="200dp" />
            </HorizontalScrollView>

你会看到我设置了一个200dp的最小宽度,这样评论永远不会太小,线程越深,它们就会越走越远屏幕。

它显示完美,但我无法水平滚动。我可以看到滚动条,但我不能水平滚动。

我已经摆弄了在RV中禁用Touch和nestedScrollingEnabled,但不确定真正的解决方案是什么。似乎什么都没有用?

任何帮助将非常感激!谢谢

android android-recyclerview horizontal-scrolling horizontalscrollview
1个回答
3
投票

删除HorizontalScrollView你可以给这样的水平方向LinearLayoutManager

LinearLayoutManager layoutManager= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
reclyclerView.setLayoutManager(layoutManager);
//recyclerView.setMinimumWidth(200); optional for width if u need
© www.soinside.com 2019 - 2024. All rights reserved.