如何以编程方式滚动的Horizo​​ntalScrollView

编程入门 行业动态 更新时间:2024-10-25 15:19:23
本文介绍了如何以编程方式滚动的Horizo​​ntalScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 Horizo​​ntalScrollView ,其中包含一个 RelativeLayout的。这种布局是空的XML,并从Java在OnCreate填充。

I have an HorizontalScrollView which contains a RelativeLayout. This layout is empty in the XML, and is populated from java in the onCreate.

我想这个滚动视图是在中间的某个地方开始的 RelativeLayout的,这是远远大于屏幕。

I would like this scroll view to be initially somewhere in the middle of the RelativeLayout, which is way larger than the screen.

我试过 mHorizScrollView.scrollTo(offsetX,0)不工作。 我不知道什么是错。

I tried mHorizScrollView.scrollTo(offsetX, 0); which doesn't work. I don't know what's wrong with this.

我可以张贴了code,但它不是真正相关。要紧的是,一切程序来完成(有:秒),而初始位置 Horizo​​ntalScrollView 已被编程设置

I could post the code, but it is not really relevant. What matters is that everything is done programatically (has to :s), and that the initial position of the HorizontalScrollView has to be set programmatically.

感谢您的阅读。请告诉我,如果你需要更多的细节,或者如果这还不够清楚。

Thanks for reading. Please tell me if you need more details or if this is not clear enough.

推荐答案

我发现,如果你延长的 Horizo​​ntalScrollView 并覆盖 onLayout ,你可以清晰地滚动,超级调用后 onLayout :

I found that if you extend the HorizontalScrollView and override the onLayout, you can cleanly scroll, after the super call to onLayout:

MyScrollView extends HorizontalScrollView { protected void onLayout (boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); this.scrollTo(wherever, 0); } }

更多推荐

如何以编程方式滚动的Horizo​​ntalScrollView

本文发布于:2023-11-11 17:57:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579159.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   Horizo   ntalScrollView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!