A bug discovered by accident

The scenario is as follows: recyclerView uses the logic of the header view. I’m not going to talk about adapter, but you can go to my TreeRecycleView library. Basically, I added a header view

ImageView  imageView = new ImageView(getContext());
 imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
headerAndFootWrapper.addHeaderView(imageView);
Copy the code

My demand, according to the data returned by the server. Dynamically set the head display to hide

public void setBanner(String url) {
        if (TextUtils.isEmpty(url)) {
            imageView.setVisibility(View.GONE);
        } else{ imageView.setVisibility(View.VISIBLE); ImageLoaderUtil.getInstance().loadImage(url, imageView); }}Copy the code

Here’s the problem:

If the header imageView is hidden. Then you can’t pull down and refresh if the header is displayed, you can pull down and refresh

Which begs the question, what the hell?

I studied it for a while.

The summary is as follows:

RecycleView all views of the first entry in RecycleView, if there is no height (e.g. WRAP_CONTENT) and view.gone is used

The SwipeRefreshLayout drop-down refresh will not trigger. Because recyclerView.childat (0).getTop() does not return a normal result.

The solution is also simple.

1. Add the header View. Remember to refresh notifyDataSetChanged() when setting view.gone