问题描述
我试图填补一些数据到 RecyclerView
与 GridLayoutManager
:
I'm trying to fill some data into a RecyclerView
with GridLayoutManager
:
GridLayoutManager layoutManager = new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false);
这将从从左至右填充数据并入电网。第一个项目将投入左上角的地方,等等。
This will fill the data into the grid from left to right. The first item will be put into top-left place, etc.
但我正在开发专为一个RTL语言,所以我需要它的填写从右到左应用
But the app I'm developing is designed for an RTL language, so I need to make it fill from right to left.
我试图改变的最后一个参数真正
。但它只是滚动的 RecyclerView
一路下滑。
I tried to change the last argument to true
. But it just scrolled the RecyclerView
all the way down.
另外设置的layoutDirection
属性为 RecyclerView
不工作(不考虑我的分API是16,这属性添加为API17 +):
Also setting layoutDirection
attribute for RecyclerView
doesn't work (without considering that my min API is 16 and this attribute is added for API17+):
<android.support.v7.widget.RecyclerView
android:id="@+id/grid"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我怎样才能创建一个使用向左填补电网的权利 RecyclerView
推荐答案
创建扩展GridLayoutMAnager类,并覆盖isLayoutRTL()方法是这样的:
Create a class that extends GridLayoutMAnager ,and override the isLayoutRTL() method like this:
public class RtlGridLayoutManager extends GridLayoutManager {
public RtlGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public RtlGridLayoutManager(Context context, int spanCount) {
super(context, spanCount);
}
public RtlGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
super(context, spanCount, orientation, reverseLayout);
}
@Override
protected boolean isLayoutRTL(){
return true;
}
}
这篇关于我怎么能由右至左填补RecyclerView与GridLayoutManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!