如何设置滚动型的起始位置? [英] How to set the starting position of a ScrollView?
本文介绍了如何设置滚动型的起始位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图设置滚动视图的初始位置,但还没有找到一种方法。没有任何人有什么想法?另外我有一个的GoogleMaps片段作为滚动视图的孩子。
I have been trying to set the initial position of a scroll View but have not found a way. Does anyone have any ideas? Also I have a GoogleMaps fragment as a children of the scroll View.
谢谢,
瑞安
推荐答案
是的,这是可能的:
ScrollView.scrollTo(int x, int y);
ScrollView.smoothScrollTo(int x, int y);
ScrollView.smoothScrollBy(int x, int y);
可用于这一点。 x和y的参数是滚动到的水平和垂直轴的坐标。
can be used for that. The x and y parameters are the coordinates to scroll to on the horizontal and vertical axis.
实例code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
sv.scrollTo(0, 100);
}
在这个例子中,一旦活动
开始,你的滚动型
将滚动下跌100像素。
In that example, once the Activity
is started, your ScrollView
will be scrolled down 100 pixels.
您也可以尝试为延迟滚动处理:
You can also try to delay the scrolling process:
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
sv.scrollTo(0, 100);
}
}, 250); // 250 ms delay
这篇关于如何设置滚动型的起始位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文