Implementation method of sliding up and down, displaying and hiding toolbar in listview

1. Prepare the toolbar

First hide the system's own actionbar in the < Application > tag of the androidmanifest.xml file:

(note that the activity here should inherit appcompatactivity)

Then add toolbar and activity in the layout file_ In the main.xml file:

Now a toolbar and a listview are added to the layout

2.Activity

(1) A headview height is added to the listview, which is consistent with the toolbar height to avoid the toolbar blocking the first item of the listview in relativelayout;

(2) Set the touch listening event of listview:

When the user presses (motionevent. Action_down) for the first time, record the start y coordinate; During the user's sliding (motionevent. Action_move), record the Y coordinate of the user's current finger; The sliding direction of the user's finger can be judged by comparing the two;

(3) Use the objectanimator class to control the animation effect of the toolbar:

Instantiate mmanimator:

(4) Use a Boolean value to identify whether the current toolbar is displayed:

If this is not the case, the ontouch method will be triggered and the toolbaranim method will be executed continuously during the continuous sliding process, resulting in poor sliding effect (this can be found from the log)

Effect achieved:

The implementation method of sliding up and down, displaying and hiding the toolbar in the listview above is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>