package com.johnwharton.quanmintv.utils;
import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import com.johnwharton.quanmintv.decoration.SpacesItemDecoration;
/**
* Created by My on 2016/9/8.
*/
public class RecyclerViewSettingsUtil {
public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
//分割线的类型,1线性 2 间隙
public static final int DECORATION_TYPE_1 = 0;
public static final int DECORATION_TYPE_2 = 1;
//线性布局固定的间隙
public static void setHorVerOrientationRecyclerView(Context context, RecyclerView recyclerView, int orientation) {
recyclerView.setHasFixedSize(true);
//设置动画
recyclerView.setItemAnimator(new DefaultItemAnimator());
//设置分割线
recyclerView.addItemDecoration(new SpacesItemDecoration(4));
LinearLayoutManager manager = null;
switch (orientation) {
case HORIZONTAL:
manager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
break;
case VERTICAL:
manager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
break;
}
recyclerView.setLayoutManager(manager);
}
//线性布局可定制的的间隙
public static void setHorVerDefSpaceRecyclerView(Context context, RecyclerView recyclerView, int orientation,int space) {
recyclerView.setHasFixedSize(true);
//设置动画
recyclerView.setItemAnimator(new DefaultItemAnimator());
//设置分割线
recyclerView.addItemDecoration(new SpacesItemDecoration(space));
LinearLayoutManager manager = null;
switch (orientation) {
case HORIZONTAL:
manager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
break;
case VERTICAL:
manager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
break;
}
recyclerView.setLayoutManager(manager);
}
/**
* 上下文环境
*
* @param context
* @param recyclerView
* @param spanCount 跨的列数目
*/
//网格布局
public static void setGridRecyclerView(Context context, RecyclerView recyclerView, int spanCount) {
recyclerView.setHasFixedSize(true);
//设置动画
recyclerView.setItemAnimator(new DefaultItemAnimator());
//设置分割线
recyclerView.addItemDecoration(new SpacesItemDecoration(4));
GridLayoutManager manager = new GridLayoutManager(context, spanCount);
//设置布局管理器
recyclerView.setLayoutManager(manager);
}
/**
* 网格布局,传入GridLayoutManager
* @param recyclerView
* @param manager
*/
public static void setGridRecyclerView(RecyclerView recyclerView, GridLayoutManager manager) {
recyclerView.setHasFixedSize(true);
//设置动画
recyclerView.setItemAnimator(new DefaultItemAnimator());
//设置分割线
recyclerView.addItemDecoration(new SpacesItemDecoration(4));
//设置布局管理器
recyclerView.setLayoutManager(manager);
}
}
工具类二、RecyclerView常用设置
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 此篇文章紧接上一篇自己常用的swift网络请求工具类(一)--NSURLSessionhttp://www.jia...
- 参考文献:《Java疯狂讲义》(第三版) Objects工具类 知识点: 它提供了一些工具方法来操作对象,这些工具...