是否可以支持旧 API 级别的类似 setScrollY() (ScrollView API 14) 的函数? [英] Is it possible to support a setScrollY() (ScrollView API 14) like function for older API levels?

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

问题描述

我正在编写一个简单的第一个 Android 应用程序.我的主要活动之一是相当长的 ScrollView.因为我有一些按钮可以调用其他 ListView.当 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) 的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆