Skip to content

Commit c11b17f

Browse files
author
lizhxian
committed
解决自定义footerview不生效的问题
1 parent 21669ff commit c11b17f

File tree

12 files changed

+664
-17
lines changed

12 files changed

+664
-17
lines changed

LRecyclerview_library/src/main/java/com/github/jdsjlzx/recyclerview/LRecyclerView.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.view.ViewConfiguration;
1515
import android.view.ViewGroup;
1616
import android.view.ViewParent;
17+
import android.widget.LinearLayout;
1718

1819
import com.github.jdsjlzx.interfaces.ILoadMoreFooter;
1920
import com.github.jdsjlzx.interfaces.IRefreshHeader;
@@ -126,10 +127,9 @@ private void init() {
126127
}
127128

128129
if (mLoadMoreEnabled) {
129-
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()));
130+
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()),false);
130131
}
131132

132-
133133
}
134134

135135
@Override
@@ -407,11 +407,18 @@ public void setRefreshHeader(IRefreshHeader refreshHeader) {
407407

408408
/**
409409
* 设置自定义的footerview
410+
* @param loadMoreFooter
411+
* @param isCustom 是否自定义footview
410412
*/
411-
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
413+
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter, boolean isCustom) {
412414
this.mLoadMoreFooter = loadMoreFooter;
415+
if (isCustom) {
416+
if (null != mWrapAdapter && mWrapAdapter.getFooterViewsCount() >0) {
417+
mWrapAdapter.removeFooterView();
418+
}
419+
}
413420
mFootView = loadMoreFooter.getFootView();
414-
mFootView.setVisibility(GONE);
421+
mFootView.setVisibility(VISIBLE);
415422

416423
//wxm:mFootView inflate的时候没有以RecyclerView为parent,所以要设置LayoutParams
417424
ViewGroup.LayoutParams layoutParams = mFootView.getLayoutParams();
@@ -420,6 +427,13 @@ public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
420427
} else {
421428
mFootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
422429
}
430+
431+
if (isCustom) {
432+
if (mLoadMoreEnabled && mWrapAdapter.getFooterViewsCount()==0) {
433+
mWrapAdapter.addFooterView(mFootView);
434+
}
435+
}
436+
423437
}
424438

425439
public void setPullRefreshEnabled(boolean enabled) {

LRecyclerview_library/src/main/java/com/github/jdsjlzx/recyclerview/LuRecyclerView.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.support.v7.widget.StaggeredGridLayoutManager;
1111
import android.util.AttributeSet;
1212
import android.view.View;
13+
import android.view.ViewGroup;
1314
import android.view.ViewParent;
1415

1516
import com.github.jdsjlzx.interfaces.ILoadMoreFooter;
@@ -104,10 +105,8 @@ public LuRecyclerView(Context context, AttributeSet attrs, int defStyle) {
104105

105106
private void init() {
106107
if (mLoadMoreEnabled) {
107-
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()));
108+
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()),false);
108109
}
109-
110-
111110
}
112111

113112
@Override
@@ -252,11 +251,33 @@ public void setNoMore(boolean noMore){
252251

253252
/**
254253
* 设置自定义的footerview
254+
* @param loadMoreFooter
255+
* @param isCustom 是否自定义footview
255256
*/
256-
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
257+
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter, boolean isCustom) {
257258
this.mLoadMoreFooter = loadMoreFooter;
259+
if (isCustom) {
260+
if (null != mWrapAdapter && mWrapAdapter.getFooterViewsCount() >0) {
261+
mWrapAdapter.removeFooterView();
262+
}
263+
}
258264
mFootView = loadMoreFooter.getFootView();
259-
mFootView.setVisibility(GONE);
265+
mFootView.setVisibility(VISIBLE);
266+
267+
//wxm:mFootView inflate的时候没有以RecyclerView为parent,所以要设置LayoutParams
268+
ViewGroup.LayoutParams layoutParams = mFootView.getLayoutParams();
269+
if (layoutParams != null) {
270+
mFootView.setLayoutParams(new LayoutParams(layoutParams));
271+
} else {
272+
mFootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
273+
}
274+
275+
if (isCustom) {
276+
if (mLoadMoreEnabled && mWrapAdapter.getFooterViewsCount()==0) {
277+
mWrapAdapter.addFooterView(mFootView);
278+
}
279+
}
280+
260281
}
261282

262283
/**

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<activity android:name=".ui.AlphaChangeActivity" />
5757
<activity android:name=".ui.QzoneHeaderActivity"/>
5858
<activity android:name=".ui.MomentsHeaderActivity"/>
59+
<activity android:name=".ui.CustomLoadingFootActivity"/>
5960
</application>
6061

6162
</manifest>

app/src/main/java/com/lzx/demo/SplashActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import android.view.animation.AccelerateDecelerateInterpolator;
1616
import android.widget.TextView;
1717

18+
import com.lzx.demo.ui.CustomLoadingFootActivity;
19+
1820
import static com.lzx.demo.R.id.textView;
1921

2022
public class SplashActivity extends AppCompatActivity implements Runnable {

app/src/main/java/com/lzx/demo/ui/CommonActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public class CommonActivity extends BaseMainActivity {
2020
AlphaChangeActivity.class,
2121
BannerHeaderLayoutActivity.class,
2222
QzoneHeaderActivity.class,
23-
MomentsHeaderActivity.class};
23+
MomentsHeaderActivity.class,
24+
CustomLoadingFootActivity.class};
2425

2526
private static final String[] TITLE = {
2627
"LinearLayoutSample",
@@ -37,7 +38,8 @@ public class CommonActivity extends BaseMainActivity {
3738
"AlphaChangeActivity",
3839
"BannerHeaderLayoutActivity",
3940
"QzoneHeaderActivity",
40-
"MomentsHeaderActivity"};
41+
"MomentsHeaderActivity",
42+
"CustomLoadingFootActivity"};
4143

4244
public Class<?>[] getActivitys() {
4345
return ACTIVITY;

0 commit comments

Comments
 (0)