Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get maximum vertical offset of collapsing toolbar layout

I currently have an AppBarLayout with a CollapsingToolbarLayout inside and I have added an OffSetChangeListener so I can rotate the dropdown arrow in my appbar when the actionbar is expanded, now everything works well except that I need the maximum vertical offset to be able to calculate the degrees to rotate and it is not provided in the listener as argument. This is my code :

appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        int slideOffset = verticalOffset*(-1);
        int slideOffsetMax = 750;

        int angle = slideOffset * 180 / slideOffsetMax;
        dropdownArrow.setRotation(angle);

    }

});

The problem is the Maximum Vertical offset varies depending on the device but if anyone has another way of achieving this feel free to show me. ps : I set my maximum offset to 750 because I logged the offset to find the maximum for my device but on my tablet its different.

like image 834
Amro elaswar Avatar asked Jul 27 '16 20:07

Amro elaswar


1 Answers

Use :

int totalScrollRange = appBarLayout.getTotalScrollRange();

to get the scrollrange of your AppBarLayout and do your calculations.

like image 103
Andre Classen Avatar answered Oct 29 '22 10:10

Andre Classen