I have a Listview and I am changing the ListView
item height dynamically inside the onScroll callback.
The issue is that I am having the following warning:
05-29 14:41:16.935: W/View(1629): requestLayout() improperly called by android.widget.RelativeLayout{42701a80 V.E..... ......ID 0,0-768,600 #7f060133 app:id/parent} during layout: running second layout pass
And the onScroll
callback is always being called, even after the user is not scrolling it, here is my code:
listview.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (adapter != null) {
for (int i = 0; i < visibleItemCount; i++) {
//the listview view
View v = adapter.getParentView(firstVisibleItem + i);
if (v != null) {
LayoutParams lp = v.getLayoutParams();
lp.height = //some height manipulation according to the view position
v.setLayoutParams(lp); //this line causes the warning
}
}
}
}
});
My goal is to change the listview items height by 1px every time depanding on the items position on the screen.
Question: how can I set the view LayoutParams
inside the onScroll
callback