Overlap Scrolling View with Appbarlayout

Overlap scrolling view with AppBarLayout

In fact, overlaying the scrolling view with the AppBarLayout is an included feature of the Android Design Support Library: you can use the app:behavior_overlapTop attribute on your NestedScrollView (or any View using ScrollingViewBehavior) to set the overlap amount:

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:behavior_overlapTop="64dp">

Note that app:behavior_overlapTop only works on views that have the app:layout_behavior="@string/appbar_scrolling_view_behavior" as it is the Behavior that is using the attribute (not the View or the Parent ViewGroup, as attributes usually apply to), hence the behavior_ prefix.

Or set it programmatically via setOverlayTop():

NestedScrollView scrollView = ...
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) scrollView.getLayoutParams();
AppBarLayout.ScrollingViewBehavior behavior =
(AppBarLayout.ScrollingViewBehavior) params.getBehavior();
behavior.setOverlayTop(128); // Note: in pixels

How to create AppBarLayout which overlaps content of CoordinatorLayout

I tried this solution, it works.

transparency :
added background to AppBarLayout, and placed scrolling view in layout before AppBarLayout

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000" >

content positioning : extended AppBarLayout.ScrollingViewBehavior by new AppbBarTransparentScrollingViewBehavior overriding onDependentViewChanged() and modifying updateOffset() to offset = 0

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
View dependency) {
updateOffset(parent, child, dependency);
return false;
}

private boolean updateOffset(CoordinatorLayout parent, View child,
View dependency) {
final CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) dependency
.getLayoutParams()).getBehavior();
if (behavior instanceof Behavior) {
// Offset the child so that it is below the app-bar (with any
// overlap)
final int offset = 0; // CHANGED TO 0
setTopAndBottomOffset(offset);
return true;
}
return false;
}

new content's behavior : set behavior on scrolling view

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout_behavior="AppbBarTransparentScrollingViewBehavior" />

result : with an ImageView inside a NestedScrollView as scrolling view

enter image description here

Android layout - NestedScrollView is overlapping AppBarLayout

Replace Constraint Layout with Coordinator Layout and it would work fine.

AppBarLayout overlaps RecyclerView

Add this attribute to the include below the toolbar:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

When you are using CoordinatorLayout and AppBarLayout, you are setting up for that coordinated scrolling where the toolbar pushes out of the way first. But in order to get that, you need to give the view below the toolbar the appbar scrolling view behavior. This not only sets up the coordinated scroll, but tells the CoordinatorLayout to layout the lower view so that it appears beneath the toolbar.

If you don't want the coordinated toolbar scrolling, replace CoordinatorLayout with a vertical LinearLayout.

Putting multiple views in CollapsingToolbarLayout overlap on one another

The first draft was without the linearlayout, but doing so the toolbar was overlapping the included layout.

You can go ahead with your first attempt, but just add a top margin that equals to the Toolbar height; which is the default ActionBar height in your case ?attr/actionBarSize.

So, this will be:

<com.google.android.material.appbar.AppBarLayout

<com.google.android.material.appbar.CollapsingToolbarLayout

<com.google.android.material.appbar.MaterialToolbar
...
android:layout_height="?attr/actionBarSize"

<include
...
android:layout_marginTop="?attr/actionBarSize"

...


Related Topics



Leave a reply



Submit