我正在尝试将一些数据填充到RecyclerView
with GridLayoutManager
:
GridLayoutManager layoutManager = new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false);
这会将数据填充到网格中左到右。第一项将被放入左上角位置,依此类推。
但我正在开发的应用程序是为 RTL 语言设计的,所以我需要让它填充右到左.
我试图将最后一个参数更改为true
。但它只是滚动了RecyclerView
一直往下。
还设置layoutDirection
属性为RecyclerView
不起作用(不考虑我的最小 API 是 16 并且此属性是为 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()
像这样的方法:
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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)