是否可以为较旧的API级别支持类似setScrollY

是否可以为较旧的API级别支持类似setScrollY

本文介绍了是否可以为较旧的API级别支持类似setScrollY()(ScrollView API 14)的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在编写的简单的Android应用程序.我的主要活动之一是相当长的ScrollView.在那我有一些调用其他ListViews的按钮.当ListViews完成并且ScrollView返回时,我希望屏幕上的位置与第一次调用ListView时的位置相同.

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.

我找到了getScrollY()和setScrollY()方法,可以实现它们以保持希望的位置.

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

但是,setScrollY()是一个API 14及更高版本的函数,根据我的应用统计,我在Gingerbread(这是一个较旧的API级别)上有很多用户.

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.

我的问题:是否有一种我已忽略或可以指出的方法,该方法可以使我在较旧的API级别上具有与setScrollY()相同的功能?

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?

推荐答案

您是否看过scrollTo(getScrollX(), y)?它在所有版本的Android中都可用.

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)

如果您查看setScrollY()的实现,则会看到:

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

public void setScrollY(int value) {
    scrollTo(mScrollX, value);
}

这篇关于是否可以为较旧的API级别支持类似setScrollY()(ScrollView API 14)的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:35