문제

I need to set an offset in the listview. I've achieved it initially by using ScrollBy(X, Y), but as soon as I touch the list view it snaps back to zero (my offset in negative).

How can I maintain this offset?

도움이 되었습니까?

해결책

If you want an empty space at the top of the ListView I would do it with a padding.

Add this to your ListView in the layout xml

android:clipToPadding="false"
android:paddingTop="25dp"

You can also do it programmatically but doing it in xml should always be preferable if possible:

float paddingTopInDp = 25.0f;

Resources resources = getResources();
float paddingTopInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingTopInDp, resources.getDisplayMetrics());
listView.setClipToPadding(false);
listView.setPadding(0, (int)(paddingTopInPixels + 0.5f), 0, 0);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top