相同的问题ScrollView .scrollTo不工作?保存在旋转滚动型位置
我动态地的onCreate项目添加到滚动视图。我尝试以下方法添加的所有项目后:
I dynamically add items to scrollView in onCreate. I try the following after all items were added:
// no effect ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); // no effect ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); mainScroll.post(new Runnable() { public void run(){ ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); mainScroll.scrollTo(0, 0); } }); // works like a charm ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); mainScroll.postDelayed(new Runnable() { public void run(){ ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); mainScroll.scrollTo(0, 0); } }, 30);
我的结论是有一些事件如DOM就绪?是否有任何回调?
I conclude that there is some event like 'DOM-ready'? Are there any callbacks?
推荐答案您不必延长滚动型和创建自己的每通过的大卫Daudelin 的this问题。
You don't need to extend the ScrollView and create your own as per the answer provided by David Daudelin for the this question.
获得 ViewTreeObserver 的滚动型并添加 OnGlobalLayoutListener 到 ViewTreeObserver 。然后调用从<$ C $的 onGlobalLayout()方法 ScrollView.scrollTo(X,Y)方法C> OnGlobalLayoutListener 。 code:
Get the ViewTreeObserver of the ScrollView and add an OnGlobalLayoutListener to the ViewTreeObserver. Then call the ScrollView.scrollTo(x,y) method from the onGlobalLayout() method of the OnGlobalLayoutListener. Code:
ScrollView mainScroll = (ScrollView) findViewById(R.id.average_scroll_mainScroll); ViewTreeObserver vto = scrollView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { mainScroll.scrollTo(0, 0); } });更多推荐
滚动型scrollTo不起作用
发布评论