Implementation method of Android listview automatically displaying and hiding layout

Use the ontouchlistener interface of view to monitor the sliding of listview, judge the sliding direction by comparing the size with the last coordinate, and judge whether to display or hide the corresponding layout through the sliding direction, with animation effect.

1. Auto show hide toolbar

First, add a headerview to the listview to avoid the first item being obscured by the toolbar.

Define an mtouchslop variable to obtain the minimum sliding distance considered by the system

Judge sliding event

Attribute animation

When using theme, use noactionbar, otherwise it will cause conflict. Also introduce compilation

2. When the component to be hidden and displayed is not a toolbar, but our custom layout MyView, we need to pay attention to some points,

(1) Relative layout should be used for layout. Let our customized layout float above listview.

(2) To avoid the first item being obscured by MyView, add a headerview to listview. At this time, you need to measure the height of MyView. Use the following method to post the task to the UI thread, otherwise there will be errors in execution.

Others are the same as toolbar

The above is the implementation method of Android listview automatic display and hiding layout introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>