[英]VerticalGridView scrolls horizontally
I finally had success adding a VerticalGridView from android support library to my project. 我终于成功地将android支持库中的VerticalGridView添加到我的项目中。 Now the problem is the grid scrolls both horizontally and vertically!
现在问题是网格水平和垂直滚动!
Here is my source : 这是我的来源:
<android.support.v17.leanback.widget.VerticalGridView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
and java code: 和java代码:
mRecyclerView = (VerticalGridView) rootView.findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNumColumns(4);
mRecyclerView.setVerticalMargin(24);
I have found a fix this. 我找到了解决方法。 You just have to set
android.support.v7.widget.GridLayoutManager
as the layout manager for the VerticalGridView
, as in the following (notice that the number of columns is passed in the constructor): 您只需将
android.support.v7.widget.GridLayoutManager
设置为VerticalGridView
的布局管理器,如下所示(请注意在构造函数中传递的列数):
mRecyclerView = (VerticalGridView) rootView.findViewById(R.id.my_recycler_view);
mRecyclerView.setLayoutManager(new GridLayoutManager(context, 4));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setVerticalMargin(24);
在leanback lib中有两个类是1. VerticalGridView 2.HorizontalGridView你可以使用HorizontalGridView进行水平滚动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.