Scroll SearchView to the top - searchView is in the middle of fragment

六眼飞鱼酱① 提交于 2021-01-29 09:49:35

问题


I have a searchView in the middle of fragment. When I tap on it, it expand a keyboard which cover list (which is under the searchView) and place for writing queries (searchView). Is there any possibility to somehow scroll to the top whole layout when tap on search icon? Currently I set all the views above searchView to myViews.visibility = View.GONE and I've received proper behaviour but I am not sure if this is correct - especially since above searchView I have a map. What's your opinion?

Greetings


回答1:


Assuming the searchComponent is a direct child of the root layout. You can simply use objectAnimator over translation y to move it to the top of the screen.

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 - is composed of the recyclerView and the searchView itself

0 is the final position of y



来源:https://stackoverflow.com/questions/59678486/scroll-searchview-to-the-top-searchview-is-in-the-middle-of-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!