Background
I've noticed an issue (link here) when adding a header view inside a ListView, in case the ListViewis inside a SwipeRefreshLayout.
The problem
The issue is that if the header view is partially visible, and you scroll up, you will see the circular view of the SwipeRefreshLayout.
You can check the link above to see a video of what I'm talking about.
Sample code
Here's how to reproduce this issue (you can check the link above in case you don't want to copy-paste) :
MainActivity.java
public class MainActivity extends ActionBarActivity
{
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ListView listView=(ListView)findViewById(android.R.id.list);
final TextView tv=new TextView(this);
tv.setText("a very large header view");
tv.setTextSize(70);
listView.addHeaderView(tv);
final SwipeRefreshLayout swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swipeToRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
swipeRefreshLayout.setRefreshing(false);
}
},1000);
}
});
final ArrayList<String> arrayList=new ArrayList<String>();
for(int i=0;i<1000;++i)
arrayList.add(Integer.toString(i));
listView.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList));
}
}
res/layout/activity_main.xml
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeToRefreshLayout"
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:fastScrollEnabled="true"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:paddingEnd="4dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingStart="4dp"
android:scrollingCache="false"
android:smoothScrollbar="false"
android:textFilterEnabled="true"/>
</android.support.v4.widget.SwipeRefreshLayout>
The question
Is there a way to solve this problem?
I guess I could use multi-types for the listView , but is there maybe another solution that is more elegant, simple or better in any other way?