问题
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