Android – prevent scrolling and expand / collapse collapsible toolbars

I used the collapsible toolbar in my application. When the activity starts, the collapsible toolbar is expanded, scrolling is enabled and works normally. But now I need to display the full screen error layout in case of my API failure. In this case, I must collapse the toolbar and the scrolling effect is blocked

The error layout shows the retry button. When I retry, I call the API again. If the API succeeds, I must expand the toolbar again and enable the scrolling effect

I can use setexpanded (flag, animate) to collapse the toolbar, but in this case, I can't prevent the scrolling effect of the collapsible toolbar and display the wrong layout at the same time

I need to provide a way to block and unblock the scrolling effect to expand / collapse the toolbar. Any help will be appreciated!!!

resolvent:

Based on the previous answer, I created a library appbarrr to lock the screen in extended mode

As I said, the height of the toolbar is the key: collapsingtoolbarlayout will collapse to the height of the toolbar and expand to the height of appbarlayout

Using this library, you must set up two layouts as toolbars and extended layouts (for locking the screen and scrolling). It will create a collapsingtoolbarlayout and expand these layouts in it

You can declare the animation duration, the color of the internal collapsingtoolbarlayout, the style of folding / expanding the title, and even lock the height of the layout... If you click it externally, you can also hide the expanded layout. It can support nestedscrollview and Scrollview in the expanded layout. A sample application is provided on the documentation and GitHub

For those who do not want to use the library, my previous answer shows how to do so. This is the output of the previous answer:

Basically, this is the same concept, but you don't need to write a complete class. To use lib, you just need to create a simple widget in XML!

Feel free to use, fork or test. I hope it will be useful;)

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