-1

I can't get the anchor to work. it doesn't follow the app bar being scrolled to the top.

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:background="@color/testGray">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_height="200dp"
        android:layout_gravity="center_horizontal"

        >
<android.support.design.widget.CollapsingToolbarLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"
    >


</android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/frame_info"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="140dp"
        android:elevation="11dp"
        android:layout_gravity="center_horizontal"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="center|bottom"
        >

    </FrameLayout>



    <team.semicolon.amizeh.CustomViews.SongsListView
        android:id="@+id/songs_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toBottomOf="@id/frame_info"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginTop="60dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

</android.support.design.widget.CoordinatorLayout>


</android.support.constraint.ConstraintLayout>

plus, I can't get the minHeight to work, It scrolls all the way to the top. I want the frame layout to follow the app bar and anchor it but the app bar scrolls but the frame layout doesn't.

MH. Abdi
  • 298
  • 5
  • 22
  • It's probably because you are using `ConstraintLayout` as the root layout instead of `CoordinatorLayout`. So, make the `CoordinatorLayout` as the root and at the top level then check. – ʍѳђઽ૯ท Aug 25 '18 at 18:38
  • I tried it, still doesn't work :( – MH. Abdi Aug 25 '18 at 19:01
  • `SongsListView` doesn't work now with anchoring? – ʍѳђઽ૯ท Aug 25 '18 at 19:02
  • the `frame_info` doesn't follow the `appbar` when I scroll, as it was supposed to do. when I scroll `SongsListView` to the top, the `appbar` moves to the top too, but `frame_info` stays in place – MH. Abdi Aug 25 '18 at 19:06

1 Answers1

0

the frame_info doesn't follow the appbar when I scroll, as it was supposed to do. when I scroll SongsListView to the top, the appbar moves to the top too, but frame_info stays in place

First of all, i don't suggest such a layout. Like i said, make the CoordinatorLayout as the root of the layout.

Also, if you are trying to achieve FrameLayout follow AppbarLayout when scrolling, you'll need to add it inside a NestedScrollView then setting the NestedScrollView:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

To follow AppbarLayout.

Check my answer about where to using above code : appbar_scrolling_view_behavior https://stackoverflow.com/a/35181870/4409113

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108