小编Jul*_* Pr的帖子

CoordinatorLayout layout_anchor不起作用

我刚刚使用CoordinatorLayout尝试了新的支持设计库,但是我在锚定子视图时遇到了问题.我的布局目前看起来像这样:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="enterAlways" />

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_anchor="@id/toolbar"
    app:layout_anchorGravity="bottom"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:src="@drawable/ic_fab_add"
    android:onClick="onAddPlayerClick"
    android:layout_gravity="bottom|end"
    app:elevation="4dp"
    app:borderWidth="0dp"/>
Run Code Online (Sandbox Code Playgroud)

加载RecyclerView列表时,操作栏会重叠第一个项目.我假设app:layout_anchor无法正常工作.我已经尝试将其锚定到appbar但没有成功.

有谁知道我在做错了什么?

android android-recyclerview android-design-library coordinator-layout

13
推荐指数
1
解决办法
3万
查看次数