Lock scrolling with panel expand / collapse collapsible panel

I used Collapsible Toolbarin my application. When you start an activity, the Foldable Toolbar has an advanced state with scrolling enabled and works normally. But now I have a requirement to show a full-screen error layout in case my API fails. In this case, I have to minimize the toolbar with the scroll effect lock.

An error button displays a redo button. In Retry, I call the API call again, and if the API succeeds, I have to expand the toolbar again and enable the scroll effect.

I managed to collapse the toolbar with setExpanded(flag, animation), but in this case I can’t block the scroll effect of the Collapsible Toolbar while the error layout is displayed.

I need to provide a way to lock, as well as unlock the scroll effect + Expand / collapse the toolbar. Any help could be helpful .. !!!

+4
source share
5 answers

I created the AppBarrr library to lock the screen in advanced mode based on my previous answer.

, Toolbar - : CollapsingToolbarLayout Toolbar AppBarLayout.

Toolbar ( ), CollapsingToolbarLayout .

, CollapsingToolbarLayout, / , ... , . NestedScrollView ScrollView . Github.


, , . :

Prevent toolbar to expand with custom error layout

, , , lib xml !


, . , ;)

+1

, . android:clickable="true" .

, .

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#f3f3f3"
      android:orientation="vertical"
      >
<!-- Add your other layout including Collapsible Toolbar here.-->

<RelativeLayout
      android:id="@+id/errorLayout"
      android:clickable="true"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      />

</RelativeLayout>
+2

AlertDialog, ProgressDialog (spinner), , , , .

0

, ,

Android: = "" , , android: visibility = "visible"

, , . , .

0
source

You can implement the interface and call its methods when you enable or disable the reset effect.

public interface AppbarRequestListener {
    void unlockAppBarOpen();

    void lockAppBarClosed();
}

 @Override
    public void unlockAppBarOpen() {
        appBarLayout.setExpanded(true, false);
        appBarLayout.setActivated(true);
        setAppBarDragging(false);
    }

    @Override
    public void lockAppBarClosed() {
        appBarLayout.setExpanded(false, false);
        appBarLayout.setActivated(false);
        setAppBarDragging(false);

    }

    private void setAppBarDragging(final boolean isEnabled) {
        CoordinatorLayout.LayoutParams params =
                (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
        AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
        behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
            @Override
            public boolean canDrag(AppBarLayout appBarLayout) {
                return isEnabled;
            }
        });
        params.setBehavior(behavior);
    } 
0
source

Source: https://habr.com/ru/post/1663404/


All Articles