Skip to content

Commit

Permalink
解决自定义footerview不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhxian committed Oct 10, 2018
1 parent 21669ff commit c11b17f
Show file tree
Hide file tree
Showing 12 changed files with 664 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.LinearLayout;

import com.github.jdsjlzx.interfaces.ILoadMoreFooter;
import com.github.jdsjlzx.interfaces.IRefreshHeader;
Expand Down Expand Up @@ -126,10 +127,9 @@ private void init() {
}

if (mLoadMoreEnabled) {
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()));
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()),false);
}


}

@Override
Expand Down Expand Up @@ -407,11 +407,18 @@ public void setRefreshHeader(IRefreshHeader refreshHeader) {

/**
* 设置自定义的footerview
* @param loadMoreFooter
* @param isCustom 是否自定义footview
*/
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter, boolean isCustom) {
this.mLoadMoreFooter = loadMoreFooter;
if (isCustom) {
if (null != mWrapAdapter && mWrapAdapter.getFooterViewsCount() >0) {
mWrapAdapter.removeFooterView();
}
}
mFootView = loadMoreFooter.getFootView();
mFootView.setVisibility(GONE);
mFootView.setVisibility(VISIBLE);

//wxm:mFootView inflate的时候没有以RecyclerView为parent,所以要设置LayoutParams
ViewGroup.LayoutParams layoutParams = mFootView.getLayoutParams();
Expand All @@ -420,6 +427,13 @@ public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
} else {
mFootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}

if (isCustom) {
if (mLoadMoreEnabled && mWrapAdapter.getFooterViewsCount()==0) {
mWrapAdapter.addFooterView(mFootView);
}
}

}

public void setPullRefreshEnabled(boolean enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

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

private void init() {
if (mLoadMoreEnabled) {
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()));
setLoadMoreFooter(new LoadingFooter(getContext().getApplicationContext()),false);
}


}

@Override
Expand Down Expand Up @@ -252,11 +251,33 @@ public void setNoMore(boolean noMore){

/**
* 设置自定义的footerview
* @param loadMoreFooter
* @param isCustom 是否自定义footview
*/
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter) {
public void setLoadMoreFooter(ILoadMoreFooter loadMoreFooter, boolean isCustom) {
this.mLoadMoreFooter = loadMoreFooter;
if (isCustom) {
if (null != mWrapAdapter && mWrapAdapter.getFooterViewsCount() >0) {
mWrapAdapter.removeFooterView();
}
}
mFootView = loadMoreFooter.getFootView();
mFootView.setVisibility(GONE);
mFootView.setVisibility(VISIBLE);

//wxm:mFootView inflate的时候没有以RecyclerView为parent,所以要设置LayoutParams
ViewGroup.LayoutParams layoutParams = mFootView.getLayoutParams();
if (layoutParams != null) {
mFootView.setLayoutParams(new LayoutParams(layoutParams));
} else {
mFootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}

if (isCustom) {
if (mLoadMoreEnabled && mWrapAdapter.getFooterViewsCount()==0) {
mWrapAdapter.addFooterView(mFootView);
}
}

}

/**
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<activity android:name=".ui.AlphaChangeActivity" />
<activity android:name=".ui.QzoneHeaderActivity"/>
<activity android:name=".ui.MomentsHeaderActivity"/>
<activity android:name=".ui.CustomLoadingFootActivity"/>
</application>

</manifest>
2 changes: 2 additions & 0 deletions app/src/main/java/com/lzx/demo/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

import com.lzx.demo.ui.CustomLoadingFootActivity;

import static com.lzx.demo.R.id.textView;

public class SplashActivity extends AppCompatActivity implements Runnable {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/lzx/demo/ui/CommonActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class CommonActivity extends BaseMainActivity {
AlphaChangeActivity.class,
BannerHeaderLayoutActivity.class,
QzoneHeaderActivity.class,
MomentsHeaderActivity.class};
MomentsHeaderActivity.class,
CustomLoadingFootActivity.class};

private static final String[] TITLE = {
"LinearLayoutSample",
Expand All @@ -37,7 +38,8 @@ public class CommonActivity extends BaseMainActivity {
"AlphaChangeActivity",
"BannerHeaderLayoutActivity",
"QzoneHeaderActivity",
"MomentsHeaderActivity"};
"MomentsHeaderActivity",
"CustomLoadingFootActivity"};

public Class<?>[] getActivitys() {
return ACTIVITY;
Expand Down
Loading

0 comments on commit c11b17f

Please sign in to comment.