将搜索视图滚动到顶部 - 搜索视图位于片段中间



我在片段中间有一个搜索视图。当我点击它时,它会展开一个键盘,该键盘覆盖列表(在搜索视图下(和用于编写查询的位置(搜索视图(。点击搜索图标时,是否有可能以某种方式滚动到顶部的整个布局?目前,我将 searchView 上方的所有视图都设置为myViews.visibility = View.GONE并且我收到了正确的行为,但我不确定这是否正确 - 特别是因为上面的 searchView 我有一张地图。你有什么意见?

问候

假设searchComponent是根布局的直接子级。您可以简单地使用翻译 y 上的objectAnimator将其移动到屏幕顶部。

var originalY = searchComponent.y // its the starting position of searchComponent which can be used to bring it back to the initial position 
val animator = ObjectAnimator.ofFloat(searchComponent, "translationY", originalY, 0)
animator.duration = 500
animator.start()

searchComponent- 由recyclerViewsearchView本身组成

0是 y 的最终位置

最新更新