Zsombor Erdődy-Nagy
Zsombor Erdődy-Nagy

Reputation: 16914

Is it possible to scroll ListView to a listrow's child element?

I have a ListView with quite "high" rows. The rows have quite complex layouts, and I'd like to get ListView to scroll to exactly a child element of a row. Is this possible?

I've only found .smoothScollToPosition(), but I can only specify a whole row in that. I need something more precise, to e.g. scroll to a child element in the middle of a row.

Thanks.

Upvotes: 5

Views: 3469

Answers (1)

David Snabel-Caunt
David Snabel-Caunt

Reputation: 58371

Take a look at the ListView method smoothScrollToPositionFromTop (inherited from AbsListView)

Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed offset pixels from the top edge of the view. If this is impossible, (e.g. the offset would scroll the first or last item beyond the boundaries of the list) it will get as close as possible. The scroll will take duration milliseconds to complete.

You'll be responsible for calculating the offset required to land in the middle of a row - that is beyond the scope of your question as it stands.

Upvotes: 4

Related Questions