Advertisement
Guest User

Untitled

a guest
May 26th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public void avoidScrollError(ListView listView, TopListAdapter listAdapter){
  2. if (listAdapter == null) {
  3. return;
  4. }
  5. int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
  6. for (int i = 0; i < listAdapter.getCount(); i++) {
  7. View listItem = listAdapter.getView(i, null, listView);
  8. if (listItem instanceof ViewGroup) {
  9. listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  10. }
  11. listItem.measure(0, 0);
  12. totalHeight += listItem.getMeasuredHeight();
  13. }
  14.  
  15. ViewGroup.LayoutParams params = listView.getLayoutParams();
  16. params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  17. listView.setLayoutParams(params);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement