In Android, the toolbar slides with Scrollview, and the transparency gradient effect is realized

In Android, the toolbar slides with Scrollview, and the transparency gradient effect is realized

1、 Idea: listen to Scrollview's sliding events and constantly modify the transparency of the toolbar

2、 Attention

1. Before Scrollview 6.0, there was no scrollview.setonscrollchangelister (L) method, so you should customize the Scrollview to listen in onscrollchanged()

2. Before Scrollview 6.0 (23), there was no Scrollview. Setonscrollchangelister() method, so we need to customize the Scrollview implementation. In order that the toolbar does not cover the Scrollview, we set paddingtop for the Scrollview

However, after the Scrollview is set to paddinttop, the toolbar transparency becomes 0, and the space occupied will be blank. Solution:

Set two properties for Scrollview:

1〉.

Indicates whether the drawing range of the control is not in padding. False means that the drawing of space can be drawn into padding

2〉

Indicates whether the child control cannot exceed the padding area (for example: false: child can slide out of the padding area when Scrollview slides up; true: child cannot slide out of the padding area when Scrollview slides up)

The layout file is as follows:

3、 Steps

1. Create callback interface:

2. Customize the Scrollview to call back the method of the translucentlistener interface in the onscrollchange method and return the alpha value:

3. Calculation of alpha value:

Finally, in mainactivity

The above is what Xiaobian introduced to you. With the Scrollview sliding transparency gradient effect of the toolbar in Android, 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
分享
二维码
< <上一篇
下一篇>>