public class BottomanSpaceItemDecoration extends RecyclerView.ItemDecoration {
private int mSpace;
private int mPosition;
private Paint paint;
private CircleSquareRvAdapter mRvAdapter;
public BottomanSpaceItemDecoration(CircleSquareRvAdapter adapter, int space, int position) {
mRvAdapter = adapter;
this.mSpace = space;
mPosition = position;
paint = new Paint();
paint.setColor(MainApplication.getInstance().getColor(R.color.red));
}
/**
* Retrieve any offsets for the given item. Each field of <code>outRect</code> specifies
* the number of pixels that the item view should be inset by, similar to padding or margin.
* The default implementation sets the bounds of outRect to 0 and returns.
* <p>
* <p>
* If this ItemDecoration does not affect the positioning of item views, it should set
* all four fields of <code>outRect</code> (left, top, right, bottom) to zero
* before returning.
* <p>
* <p>
* If you need to access Adapter for additional data, you can call
* {@link RecyclerView#getChildAdapterPosition(View)} to get the adapter position of the
* View.
*
* @param outRect Rect to receive the output.
* @param view The child view to decorate
* @param parent RecyclerView this ItemDecoration is decorating
* @param state The current state of RecyclerView.
*/
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
/*outRect.left = mSpace;
outRect.right = mSpace;
outRect.bottom = mSpace;*/
int position = parent.getChildAdapterPosition(view);
if(mPosition == -1){
mPosition = mRvAdapter.mTabPosition == 0 ? -1 : mRvAdapter.mTabPosition;
}
if (position > mPosition && mPosition != -1) {
outRect.bottom = mSpace;
}
}
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
int left = parent.getPaddingLeft();
int right = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = parent.getChildAt(i);
float top = view.getTop() - mSpace;
float bottom = view.getTop();
int position = parent.getChildAdapterPosition(view);
if(mPosition == -1){
mPosition = mRvAdapter.mTabPosition == 0 ? -1 : mRvAdapter.mTabPosition;
}
if (position > mPosition && mPosition != -1) {
c.drawRect(left, top, right, bottom, paint);//绘制红色矩形
}
/*long groupId = callback.getGroupId(position);
if (groupId < 0) return;
String textLine = callback.getGroupFirstLine(position).toUpperCase();
if (position == 0 || isFirstInGroup(position)) {
float top = view.getTop() - topGap;
float bottom = view.getTop();
c.drawRect(left, top, right, bottom, paint);//绘制红色矩形
c.drawText(textLine, left, bottom, textPaint);//绘制文本
}*/
}
}
}
相关推荐
Android RecyclerView 间距全适配
RecyclerView自定义行列间距
浅谈Android RecyclerView 间距全适配
本篇文章主要介绍了浅谈Android RecyclerView 间距全适配,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
RecyclerView加载不同布局(有间距)
RecyclerView加载不同布局(有间距)。
RecycleView设置行间距
1/ rvDataInfo.setLayoutManager(new FlowLayoutManager()); //设置每一个item间距 rvDataInfo.addItemDecoration(new SpaceItemDecoration(DisplayUtil.dp2px(getApplicationContext(), 10)))...
【Android】RecyclerView实现列表中的Item之间设置间距的一种方式
RecyclerView实现列表中的Item之间设置间距的一种方式
android recyclerView行间距、列间距太大、不对称的解决
发现的问题: 1.当List排行是水平滑动时,行间距很大 2.当List排行是竖直滑动时,列间距很大 解决方案: 1.item的布局 改为 android:layout_width=“wrap_content” android:layout_height=“match_parent” 2.item的布局 改为 android:layout_width=“match_parent” android:layout_height=“wrap_content” ...
自定义RecyclerView间距
自定义RecyclerView间距(上下左右都一样间距) 直接上代码(自定义间距,继承RecyclerView.ItemDecoration 利用getItemOffsets()里面修改): /** * 自定义recyclerView间距,(上下左右都一样间距) * @author 2216264142@qq.com **/ public class CustomizeItemDecoration extends RecyclerView.ItemDecoration { /**
RecyclerView的行间距&&RecyclerView的Item间距&&
新建立一个工具类起名SpaceItemDecoration public class SpacesItemDecoration extends RecyclerView.ItemDecoration {//设置每个Item的间距 private int space; public SpacesItemDecoration(int space) { t
RecyclerView网格布局间距设置
import android.graphics.Rect; import android.util.Log; import android.view.View; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; /** * created */ public class GridSpaceItemDecoration extends RecyclerView.ItemDeco.
android 记录笔记
自己笔记 每天时时刻刻都会更新 看到好就会添加进来 oncreate和oncreateview的区别 onCreate是指创建该fragment类似于Activity.onCreate,你可以在其中初始化除了view之外的东西,onCreateView是创建该fragment对应的视图,你必须在这里创建自己的视图并返回给调用者,例如 return inflater.inflate(R.l
关于Recycler的一些笔记
RecyclerView: 在viewHolder中不需要传递RecyclerView,使用: onAttachedToRecyclerView(RecyclerView recyclerView)方法可以获取使用该ViewHolder的RecyclerView的对象 onDatachedFromRecyclerView(RecyclerView recyclerView)方法接触绑定,这两
RecyclerView GridLayoutManager 等分间距
RecyclerView 表格实现 RecyclerView 配合GridLayoutManager 可以实现类似表格的样式,为了实现均分,adapter 的布局宽度改为匹配父元素,即 android:layout_width=“match_parent” 。 RecyclerView rvPhotoAlbums = findViewById(R.id.rv_photoAlbums_conten...
解决ScrollView嵌套RecyclerView只显示一行的问题
解决ScrollView嵌套RecyclerView只显示一行的问题
android grid分割线,Recyclerview设置GridLayoutManager分割线
public class GridSpaceItemDecoration extends RecyclerView.ItemDecoration {private int mSpanCount;//横条目数量private int mRowSpacing;//行间距private int mColumnSpacing;// 列间距/*** @param spanCount 列数* @par...
流式布局实现历史记录效果
流式布局实现历史记录效果
Android RecyclerView设置间距
我现在要完成这个图形 recycleview默认是没有间距的,我们要手动设置 rl_daily.setLayoutManager(new GridLayoutManager(getContext(), 3)); recycleViewAdapter = new RecycleViewAdapter(list); rl_daily.setAdapter(recycleViewAdapter...
Android开发-RecyclerView-AndroidStudio(八)属性动画(5)ItemDecoration
这里演示,我们用于实现类似ListView的分割线效果。 因为RecyclerView还有水平、瀑布流等布局,所有分割线 的宽度,是可以设置上下左右的,而不是只有间距。 简单的看一下代码和动态效果图,最下面有项目源码: // 使用绘制方法 实现数据行间距效果 recycler.addItemDecoration(new RecyclerView.Item
RecyclerView使用GridLayoutManager间距设置
使用RecyclerView设置间距,需要重写RecyclerView.ItemDecoration这个类。有如下的效果图需要实现,间距只有中间的格子和底部的格式之间有。 实现方法很简单,因为这个效果是每一行有3个格子,只要每行的第一个格式左边间距为0即可以。其他都设置左边距和底部距离。 代码如下: public class SpaceItemDecoration extends
RecyclerView 间距
转自:http://stackoverflow.com/questions/28531996/android-recyclerview-gridlayoutmanager-column-spacing RecyclerViews support the concept of ItemDecoration: special offsets and drawing around each
1908




被折叠的 条评论
为什么被折叠?



