Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created June 19, 2017 07:06
Show Gist options
  • Save talhahasanzia/6f57c3ab970b136fb43c2a4809b4a28d to your computer and use it in GitHub Desktop.
Save talhahasanzia/6f57c3ab970b136fb43c2a4809b4a28d to your computer and use it in GitHub Desktop.
Listview with extra spaces (padding)
public class MyListView extends ListView
{
private android.view.ViewGroup.LayoutParams params;
private int oldCount = 0;
public MyListView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas)
{
if (getCount() != oldCount)
{
int height = getChildAt(0).getHeight() + 3 ;
oldCount = getCount();
params = getLayoutParams();
params.height = (getCount()) * height;
setLayoutParams(params);
}
super.onDraw(canvas);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment