Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to support a setScrollY() (ScrollView API 14) like function for older API levels?

I have a simple first Android app that I am coding. One of my main activities is a ScrollView that's fairly long. In that I have some buttons that call other ListViews. When the ListViews are finished and the ScrollView is back I want the position on the screen to be the same as what it was when the ListView was first called.

I found the getScrollY() and setScrollY() methods and can implement them to keep the position the way I wish.

However, the setScrollY() is an API 14 and up function, and according to my app statistics I have a lot of users on Gingerbread, which is an older API level.

My Question: Is there a method that I have overlooked or can be pointed towards that allows me to have the same functionality as setScrollY() on the older API levels?

like image 594
JollyRoberts Avatar asked Mar 18 '13 20:03

JollyRoberts


1 Answers

Have you looked at scrollTo(getScrollX(), y)? It's available in all versions of Android.

http://developer.android.com/reference/android/view/View.html#scrollTo(int%2C%20int)

If you look at the implementation of setScrollY(), you'll see:

public void setScrollY(int value) {
    scrollTo(mScrollX, value);
}
like image 126
Tushar Avatar answered Sep 28 '22 18:09

Tushar