integers = DataUtils.produceImageList(R.mipmap.ty1, 30);
40 | ImageAdapter imageAdapter = new ImageAdapter(this, integers);
41 | mRecyclerView.setAdapter(imageAdapter);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.xj.recyclerviewdemo.grid.GridSampleActivity;
9 | import com.xj.recyclerviewdemo.grid.GridSampleActivity2;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 | }
18 |
19 | public void onButtonClick(View view) {
20 | switch (view.getId()) {
21 | case R.id.btn_0:
22 | startActivity(new Intent(this, DividerSampleActivity.class));
23 | break;
24 | case R.id.btn_1:
25 | startActivity(new Intent(this, GridSampleActivity.class));
26 | break;
27 | case R.id.btn_2:
28 | startActivity(new Intent(this, LinearSampleActivity.class));
29 | break;
30 | case R.id.btn_3:
31 | startActivity(new Intent(this, GridSampleActivity2.class));
32 | break;
33 | default:
34 | break;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/RecyclerViewDivider.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Drawable;
10 | import android.support.v4.content.ContextCompat;
11 | import android.support.v7.widget.LinearLayoutManager;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.util.Log;
14 | import android.view.View;
15 |
16 |
17 | /**
18 | * 博客地址:http://blog.csdn.net/gdutxiaoxu
19 | *
20 | * @author xujun
21 | * @time 19-4-17
22 | */
23 | public class RecyclerViewDivider extends RecyclerView.ItemDecoration {
24 |
25 | private static final String TAG = "RecyclerViewDivider";
26 |
27 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
28 | private static final int DIVIDER_COLOR = Color.parseColor("#efefef");
29 |
30 | private Paint mPaint;
31 | private Drawable mDivider;
32 | private int mDividerHeight = 1;
33 |
34 | //The direction of the list:LinearLayoutManager.VERTICAL or LinearLayoutManager.HORIZONTAL
35 | private int mOrientation;
36 | private int mLeftOffset;
37 | private int mRightOffset;
38 | private boolean mIsShowLastDivider;
39 | private int mDividerColor;
40 | private int mStart = 0;
41 | private int mEnd = 0;
42 |
43 |
44 | public RecyclerViewDivider(Context context) {
45 | this(context, LinearLayoutManager.VERTICAL, 1, DIVIDER_COLOR);
46 | }
47 |
48 | public RecyclerViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) {
49 | this(context, orientation);
50 |
51 | mDividerColor = dividerColor;
52 | mDividerHeight = dividerHeight;
53 |
54 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
55 | mPaint.setColor(dividerColor);
56 | mPaint.setStyle(Paint.Style.FILL);
57 | }
58 |
59 | public RecyclerViewDivider(Context context, int orientation) {
60 | if (orientation != LinearLayoutManager.VERTICAL
61 | && orientation != LinearLayoutManager.HORIZONTAL) {
62 | throw new IllegalArgumentException("Please input right parameter");
63 | }
64 |
65 | mOrientation = orientation;
66 |
67 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
68 | mDivider = a.getDrawable(0);
69 | a.recycle();
70 | }
71 |
72 | public RecyclerViewDivider(Context context, int orientation, int drawableId) {
73 | this(context, orientation);
74 |
75 | mDivider = ContextCompat.getDrawable(context, drawableId);
76 | mDividerHeight = mDivider.getIntrinsicHeight();
77 | }
78 |
79 | /**
80 | * Set the offset of the horizontal split line
81 | *
82 | * @param leftOffset
83 | * @param rightOffset
84 | */
85 | public void setHorizontaloffset(int leftOffset, int rightOffset) {
86 | mLeftOffset = leftOffset;
87 | mRightOffset = rightOffset;
88 | }
89 |
90 | /**
91 | * Set whether to display the last split line, not displayed by default
92 | *
93 | * @param isShowLastDivider
94 | */
95 | public void setShowLastDivider(boolean isShowLastDivider) {
96 | mIsShowLastDivider = isShowLastDivider;
97 | }
98 |
99 | /**
100 | * split line display range
101 | *
102 | * fisrt = 0 + start;
103 | * last = childSize - 1 - end - mIsShowLastDivider ? 0 : 1
104 | *
105 | * @param start
106 | * @param end
107 | */
108 | public void setDividerStartAndEndOffsetCount(int start, int end) {
109 | mStart = start;
110 | mEnd = end;
111 | }
112 |
113 | public void setDividerHeight(int dividerHeight) {
114 | mDividerHeight = dividerHeight;
115 | }
116 |
117 | public void setDividerColor(int dividerColor) {
118 | mDividerColor = dividerColor;
119 | if (mPaint != null) {
120 | mPaint.setColor(mDividerColor);
121 | }
122 | }
123 |
124 | @Override
125 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
126 | super.getItemOffsets(outRect, view, parent, state);
127 | outRect.set(0, 0, 0, mDividerHeight);
128 | }
129 |
130 | @Override
131 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
132 | super.onDraw(c, parent, state);
133 | if (mOrientation == LinearLayoutManager.VERTICAL) {
134 | drawVerticalDivider(c, parent);
135 | } else {
136 | drawHorizontalDivider(c, parent);
137 | }
138 | }
139 |
140 | //Draw item dividing line
141 | private void drawVerticalDivider(Canvas canvas, RecyclerView parent) {
142 | // mLeftOffset 为自己设置的左边偏移量
143 | final int left = parent.getPaddingLeft() + mLeftOffset;
144 | // mRightOffset 为设置的右边偏移量
145 | final int right = parent.getMeasuredWidth() - parent.getPaddingRight() + mRightOffset;
146 | final int childSize = parent.getChildCount();
147 |
148 | if (childSize <= 0) {
149 | return;
150 | }
151 |
152 | // 从第一个 item 开始绘制
153 | int first = mStart;
154 | // 到第几个 item 绘制结束
155 | int last = childSize - mEnd - (mIsShowLastDivider ? 0 : 1);
156 | Log.d(TAG, " last = " + last + " childSize =" + childSize + "left = " + left);
157 |
158 | if (last <= 0) {
159 | return;
160 | }
161 |
162 | for (int i = first; i < last; i++) {
163 | drawableVerticalDivider(canvas, parent, left, right, i, mDividerHeight);
164 | }
165 |
166 | }
167 |
168 | private void drawableVerticalDivider(Canvas canvas, RecyclerView parent, int left, int right, int i, int dividerHeight) {
169 | final View child = parent.getChildAt(i);
170 |
171 | if (child == null) {
172 | return;
173 | }
174 |
175 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
176 | final int top = child.getBottom() + layoutParams.bottomMargin;
177 | final int bottom = top + dividerHeight;
178 |
179 | // 适配 drawable
180 | if (mDivider != null) {
181 | mDivider.setBounds(left, top, right, bottom);
182 | mDivider.draw(canvas);
183 | }
184 |
185 | // 适配分割线
186 | if (mPaint != null) {
187 | canvas.drawRect(left, top, right, bottom, mPaint);
188 | }
189 | }
190 |
191 | // Draw vertical item dividing line
192 | private void drawHorizontalDivider(Canvas canvas, RecyclerView parent) {
193 | final int top = parent.getPaddingTop();
194 | final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
195 | final int childSize = parent.getChildCount();
196 |
197 | for (int i = 0; i < childSize; i++) {
198 | final View child = parent.getChildAt(i);
199 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
200 | final int left = child.getRight() + layoutParams.rightMargin;
201 | final int right = left + mDividerHeight;
202 |
203 | if (mDivider != null) {
204 | mDivider.setBounds(left, top, right, bottom);
205 | mDivider.draw(canvas);
206 | }
207 |
208 | if (mPaint != null) {
209 | canvas.drawRect(left, top, right, bottom, mPaint);
210 | }
211 | }
212 | }
213 |
214 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/TextAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo;
2 |
3 | import android.content.Context;
4 | import android.widget.TextView;
5 |
6 | import com.xj.library.recyclerView.CommonAdapter;
7 | import com.xj.library.recyclerView.base.ViewHolder;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by jun xu on 19-4-10.
13 | */
14 | public class TextAdapter extends CommonAdapter {
15 |
16 | public TextAdapter(Context context, List datas) {
17 | super(context, R.layout.item_divider, datas);
18 | }
19 |
20 | @Override
21 | protected void convert(ViewHolder holder, String s, int position) {
22 | TextView tvMsg = holder.getView(R.id.tv_msg);
23 | tvMsg.setText(s);
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/grid/GridSampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo.grid;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 |
8 | import com.xj.library.utils.DisplayUtils;
9 | import com.xj.recyclerviewdemo.DataUtils;
10 | import com.xj.recyclerviewdemo.GridDividerItemDecoration;
11 | import com.xj.recyclerviewdemo.R;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * 博客地址:http://blog.csdn.net/gdutxiaoxu
17 | * @author xujun
18 | * @time 19-4-17
19 | */
20 | public class GridSampleActivity extends AppCompatActivity {
21 |
22 | RecyclerView mRecyclerView;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_grid_sample);
28 | initView();
29 | }
30 |
31 | private void initView() {
32 | mRecyclerView = findViewById(R.id.recycler_view);
33 | GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
34 |
35 | mRecyclerView.setLayoutManager(layoutManager);
36 | int firstAndLastColumnW = DisplayUtils.dp2px(this, 15);
37 | int firstRowTopMargin = DisplayUtils.dp2px(this, 15);
38 | GridDividerItemDecoration gridDividerItemDecoration =
39 | new GridDividerItemDecoration(this, firstAndLastColumnW, firstRowTopMargin, firstRowTopMargin);
40 | gridDividerItemDecoration.setFirstRowTopMargin(firstRowTopMargin);
41 | gridDividerItemDecoration.setLastRowBottomMargin(firstRowTopMargin);
42 | mRecyclerView.addItemDecoration(gridDividerItemDecoration);
43 | List imageList = DataUtils.produceImageList(30);
44 | ImageAdapter imageAdapter = new ImageAdapter(this, imageList);
45 |
46 | mRecyclerView.setAdapter(imageAdapter);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/grid/GridSampleActivity2.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo.grid;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 |
8 | import com.xj.library.utils.DisplayUtils;
9 | import com.xj.recyclerviewdemo.DataUtils;
10 | import com.xj.recyclerviewdemo.GridDividerItemDecoration;
11 | import com.xj.recyclerviewdemo.R;
12 |
13 | import java.util.List;
14 |
15 | public class GridSampleActivity2 extends AppCompatActivity {
16 |
17 |
18 | public static final int SPAN_COUNT = 3;
19 | RecyclerView mRecyclerView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_grid_sample);
25 | initView();
26 | }
27 |
28 | private void initView() {
29 | mRecyclerView = findViewById(R.id.recycler_view);
30 | GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
31 |
32 | mRecyclerView.setLayoutManager(layoutManager);
33 | int firstAndLastColumnW = DisplayUtils.dp2px(this, 15);
34 | int firstRowTopMargin = DisplayUtils.dp2px(this, 15);
35 | GridDividerItemDecoration gridDividerItemDecoration =
36 | new GridDividerItemDecoration(this, firstAndLastColumnW, firstRowTopMargin, firstRowTopMargin);
37 | gridDividerItemDecoration.setFirstRowTopMargin(firstRowTopMargin);
38 | gridDividerItemDecoration.setLastRowBottomMargin(firstRowTopMargin);
39 | int itemWidth = (DisplayUtils.getScreenWidth(this)
40 | - DisplayUtils.dp2px(this, 20) * (SPAN_COUNT - 1) - firstAndLastColumnW * 2) / SPAN_COUNT;
41 |
42 | mRecyclerView.addItemDecoration(gridDividerItemDecoration);
43 | List imageList = DataUtils.produceImageList(30);
44 | ImageAdapter imageAdapter = new ImageAdapter(this, imageList);
45 | imageAdapter.setWidth(itemWidth);
46 | mRecyclerView.setAdapter(imageAdapter);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xj/recyclerviewdemo/grid/ImageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo.grid;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.DrawableRes;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.xj.library.recyclerView.CommonAdapter;
12 | import com.xj.library.recyclerView.base.ViewHolder;
13 | import com.xj.recyclerviewdemo.R;
14 |
15 | import java.util.List;
16 |
17 | /**
18 | * 博客地址:http://blog.csdn.net/gdutxiaoxu
19 | *
20 | * @author xujun
21 | * @time 19-4-17
22 | */
23 | public class ImageAdapter extends CommonAdapter {
24 |
25 | private static final String TAG = "ImageAdapter";
26 |
27 | private int mWidth;
28 |
29 | public ImageAdapter(Context context, List datas) {
30 | super(context, R.layout.item_image, datas);
31 | }
32 |
33 | public void setWidth(int width) {
34 | mWidth = width;
35 | }
36 |
37 |
38 | @Override
39 | protected void onViewHolderCreate(ViewGroup parent, ViewHolder holder, int viewType) {
40 | super.onViewHolderCreate(parent, holder, viewType);
41 | View convertView = holder.getConvertView();
42 | Log.i(TAG, "onViewHolderCreate: mWidth =" + mWidth);
43 | if (mWidth > 0) {
44 | convertView.getLayoutParams().width = mWidth;
45 | }
46 |
47 |
48 | }
49 |
50 | @Override
51 | protected void convert(ViewHolder holder, @DrawableRes Integer integer, int position) {
52 | ImageView iv = holder.getView(R.id.iv);
53 | Glide.with(mContext).load(integer).into(iv);
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_divider_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_grid_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_grid_sample2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_linear_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
26 |
27 |
34 |
35 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_divider.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ty.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xhdpi/ty.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ty1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xxhdpi/ty1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RecyclerViewDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/xj/recyclerviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xj.recyclerviewdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
29 | apply from:"config.gradle"
30 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | // Sdk and tools
3 | minSdkVersion = 15
4 | targetSdkVersion = 28
5 | // targetSdkVersion = 22
6 | compileSdkVersion = 28
7 | buildToolsVersion = '28.0.3'
8 | sourceCompatibilityVersion = JavaVersion.VERSION_1_8
9 | targetCompatibilityVersion = JavaVersion.VERSION_1_8
10 | okhttp3Version = '3.0.1'
11 | supportLibraryVersion = '27.1.0'
12 |
13 | // App dependencies
14 | supportLibraryVersion = '27.1.0'
15 | guavaVersion = '18.0'
16 | junitVersion = '4.12'
17 | mockitoVersion = '1.10.19'
18 | powerMockito = '1.6.2'
19 | hamcrestVersion = '1.3'
20 | runnerVersion = '0.5'
21 | rulesVersion = '0.5'
22 | espressoVersion = '2.2.2'
23 |
24 |
25 | dep = [
26 | androidPlugin : 'com.android.tools.build:gradle:2.1.3',
27 | okhttp : 'com.squareup.okhttp:okhttp:2.7.1',
28 | okhttp3 : "com.squareup.okhttp3:okhttp:$okhttp3Version",
29 | mockWebServer : "com.squareup.okhttp3:mockwebserver:$okhttp3Version",
30 | pollexor : 'com.squareup:pollexor:2.0.0',
31 | supportV4 : "com.android.support:support-v4:$supportLibraryVersion",
32 | supportAnnotations : "com.android.support:support-annotations:$supportLibraryVersion",
33 | junit : 'junit:junit:4.10',
34 | fest : 'org.easytesting:fest-assert-core:2.0M10',
35 | festAndroid : 'com.squareup:fest-android:1.0.6',
36 | robolectric : 'org.robolectric:robolectric:3.1',
37 | mockito : 'org.mockito:mockito-core:1.9.5',
38 | // Android support 相关库
39 | "appcompat-v7" : "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion",
40 | "cardview-v7" : "com.android.support:cardview-v7:$rootProject.supportLibraryVersion",
41 | "design" : "com.android.support:design:$rootProject.supportLibraryVersion",
42 | "recyclerview-v7" : "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion",
43 | "support-v4" : "com.android.support:support-v4:$rootProject.supportLibraryVersion",
44 | "percent" : "com.android.support:percent:$rootProject.supportLibraryVersion",
45 | // 网络与rxjava
46 | "retrofit" : 'com.squareup.retrofit2:retrofit:2.1.0',
47 | "converter-gson" : 'com.squareup.retrofit2:converter-gson:2.1.0',
48 | "adapter-rxjava" : 'com.squareup.retrofit2:adapter-rxjava:2.1.0',
49 | "converter-gson" : 'com.squareup.retrofit2:converter-gson:2.1.0',
50 | "okhttp3:interceptor": 'com.squareup.okhttp3:logging-interceptor:3.3.1',
51 | "rxjava" : 'io.reactivex:rxjava:1.1.0',
52 | "rxandroid" : 'io.reactivex:rxandroid:1.1.0',
53 | // 图片加载
54 | "picasso" : 'com.squareup.picasso:picasso:2.5.2',
55 | "glide" : 'com.github.bumptech.glide:glide:3.7.0',
56 | "glide:okhttp3" : 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar',
57 |
58 | "gson" : 'com.google.code.gson:gson:2.8.0',
59 |
60 | // 事件总线
61 | "androideventbus" : 'org.simple:androideventbus:1.0.5.1',
62 |
63 | // 数据库
64 | "litepal" : 'org.litepal.android:core:1.3.2',
65 |
66 |
67 | "fab" : 'com.github.clans:fab:1.6.4',
68 | // 动画兼容
69 | "nineoldandroids" : 'com.nineoldandroids:library:2.4.0',
70 | // 下拉刷新
71 | "refreshlayout" : 'cn.bingoogolapple:bga-refreshlayout:1.1.6@aar',
72 | "logger" : 'com.orhanobut:logger:1.15',
73 |
74 | "xrecyclerview" : 'com.jcodecraeer:xrecyclerview:1.3.2',
75 | "getui" : 'com.getui:sdk:2.10.2.0',
76 |
77 |
78 | // implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
79 |
80 |
81 | ]
82 |
83 | isCi = "true".equals(System.getenv('CI'))
84 | }
85 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gdutxiaoxu/RecyclerViewSample/d05e8c00dd7ff835df340d47e8fd7ae33a6cf583/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app',":submodules:BaseLibrary"
2 |
--------------------------------------------------------------------------------