协调器布局锚不起作用

问题描述 投票:-1回答:1

我无法让锚点工作。它不会跟随应用栏滚动到顶部。

 <?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>

另外,我无法让minHeight工作,它一直滚动到顶部。我希望框架布局跟随应用程序栏并锚定它但应用程序栏滚动但框架布局不滚动。

android android-xml android-coordinatorlayout
1个回答
0
投票

当我滚动时,frame_info不会跟随appbar,就像它应该做的那样。当我将SongsListView滚动到顶部时,appbar也会移到顶部,但frame_info保持不变

首先,我不建议这样的layout。就像我说的那样,将CoordinatorLayout作为布局的根源。

另外,如果你想要实现FrameLayout在滚动时跟随AppbarLayout,你需要在NestedScrollView中添加它然后设置NestedScrollView

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

关注AppbarLayout

检查我的答案,关于在哪里使用上面的代码:appbar_scrolling_view_behavior https://stackoverflow.com/a/35181870/4409113

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.