Sup*_*ale 0 android horizontal-scrolling horizontalscrollview android-recyclerview
我在水平滚动视图中使用 Recycler 视图来显示线程注释,如下所示:
Comment1 Comment1Child1 Comment1Child2 Comment1Child2Child1 Comment1Child3 Comment2
等等。
我使用以下 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>
Run Code Online (Sandbox Code Playgroud)
你会看到我设置了一个 200dp 的最小宽度,这样评论永远不会变得太小,而且在线程越往下,它会被推到离屏幕越远的地方。
它显示完美,但我无法水平滚动。我可以看到滚动条,但无法水平滚动。
我在 RV 中尝试了禁用 Touch 和nestedScrollingEnabled,但不确定真正的解决方案是什么。似乎没有任何效果?
任何帮助将非常感激!谢谢
删除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
Run Code Online (Sandbox Code Playgroud)