Created
June 19, 2017 07:06
-
-
Save talhahasanzia/6f57c3ab970b136fb43c2a4809b4a28d to your computer and use it in GitHub Desktop.
Listview with extra spaces (padding)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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