Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你能在滚动视图中画一个矩形吗?如果有怎么办?我进行了一些搜索,但找不到答案。具体来说,我希望滚动视图中的矩形,这样当我滚动矩形时,矩形会随着视图移动,而不是矩形位于滚动视图的顶部,滚动视图将在矩形下方滚动,矩形将保持在它的顶部是。
您需要创建一个扩展ScrollView和覆盖的类onDraw()。在那里你可以画任何你想要的东西。要使绘图随内容滚动,您应该使用通过getScrollX()或获得的值偏移位置getScrollY()。
ScrollView
onDraw()
getScrollX()
getScrollY()