version:
update:优化item分割,更新gradle配置 bugfixes:
This commit is contained in:
@@ -10,11 +10,10 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
public class EquallyDividedItemDecoration extends RecyclerView.ItemDecoration {
|
||||
private static final String TAG = EquallyDividedItemDecoration.class.getSimpleName();
|
||||
|
||||
private int mSpanCount;//横条目数量
|
||||
private int mHalfRowSpacing;//行间距的一半
|
||||
private int mSpanCount;// 横条目数量
|
||||
private int mHalfRowSpacing;// 行间距的一半
|
||||
private int mHalfColumnSpacing;// 列间距的一半
|
||||
|
||||
|
||||
public EquallyDividedItemDecoration(int spanCount, int halfRowSpacing) {
|
||||
mSpanCount = spanCount;
|
||||
mHalfRowSpacing = halfRowSpacing;
|
||||
@@ -28,12 +27,13 @@ public class EquallyDividedItemDecoration extends RecyclerView.ItemDecoration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
|
||||
@NonNull RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
int position = parent.getChildAdapterPosition(view); // 获取view 在adapter中的位置。
|
||||
Log.d(TAG, "getItemOffsets: position = " + position);
|
||||
|
||||
int itemCount = parent.getAdapter().getItemCount();//item全部数量
|
||||
int itemCount = parent.getAdapter().getItemCount();// item全部数量
|
||||
Log.d(TAG, "getItemOffsets: itemCount = " + itemCount);
|
||||
|
||||
int column = position % mSpanCount; // view 所在的列
|
||||
@@ -50,9 +50,9 @@ public class EquallyDividedItemDecoration extends RecyclerView.ItemDecoration {
|
||||
outRect.right = mHalfRowSpacing;
|
||||
}
|
||||
|
||||
int row = (position / 3);//所在行
|
||||
int row = (position / mSpanCount);// 所在行
|
||||
Log.d(TAG, "getItemOffsets: row = " + row);
|
||||
int maxRow = (int) Math.ceil((double) itemCount / mSpanCount);//一共多少行
|
||||
int maxRow = (int) Math.ceil((double) itemCount / mSpanCount);// 一共多少行
|
||||
Log.d(TAG, "getItemOffsets: maxRow = " + maxRow);
|
||||
|
||||
if (row == 0) {
|
||||
|
||||
15
build.gradle
15
build.gradle
@@ -5,7 +5,11 @@ buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url 'https://developer.huawei.com/repo/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/central/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.6.3'
|
||||
@@ -19,10 +23,11 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven { url "https://www.jitpack.io" }
|
||||
maven { url "https://maven.aliyun.com/repository/public" } //jcenter & central
|
||||
maven { url "https://maven.aliyun.com/repository/google" }
|
||||
mavenCentral()
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url 'https://developer.huawei.com/repo/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/central/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/public/' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user