I'm using the example coordinator layour provided in Android Studio and I replaced the FloatingActionButton for a custom view. I've noticed that the FloatingActionButton hides when the app scrolls down using a CollapsingToolbarLayout and I need to replicate that behavior with my custom view.
Here is The XML of the Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_model" />
<com.github.lzyzsd.circleprogress.CircleProgress
android:id="@+id/day_circle"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
custom:circle_prefix_text="$ "
custom:circle_suffix_text=""/>
This is How it looks when it's expanded:

And this is how it looks when it's collapsed:

Do you have any idea how can I replicate the FloatingActionButton behavior and hide the custom view (Circular progress bar) when the toolbar collapses?
Thank you in advance.
public class CircleProgressBehavior extends CoordinatorLayout.Behavior<CircleProgress> {
public CircleProgressBehavior(Context context, AttributeSet attrs) {
...
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, CircleImageView child, View dependency) {
...
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {
...
}
@Override
private void shouldInitProperties(CircleImageView child, View dependency) {
...
}
}
The XML of Layout
<com.github.lzyzsd.circleprogress.CircleProgress
android:id="@+id/day_circle"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:layout_behavior=".CircleProgressBehavior"
custom:circle_prefix_text="$ "
custom:circle_suffix_text=""/>
Sample Code on Github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With