CoordinatorLayout layout_anchor不起作用 [英] CoordinatorLayout layout_anchor does not work
本文介绍了CoordinatorLayout layout_anchor不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚使用CoordinatorLayout尝试了新的支持设计库,但是在锚定子视图时遇到了问题.我的布局目前看起来像这样:
I just tried out the new Support Design Library with CoordinatorLayout, but I'm having problems anchoring child views. My layout currently looks like this:
<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"/>
加载RecyclerView列表时,操作栏将覆盖第一项.我认为app:layout_anchor无法正常工作.我已经尝试将其锚定到appbar失败.
When the RecyclerView list is loaded, the first item is being overlapped by the action bar. I assume the app:layout_anchor is not working properly. I already tried anchoring it to appbar to no success.
有人知道我在做什么错吗?
Does anyone know what I am doing wrong here?
推荐答案
尝试此代码.您需要在RecyclerView
Try this code. You need to use app:layout_behavior
in your RecyclerView
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_fab_add"
android:onClick="onAddPlayerClick"
app:elevation="4dp"
app:borderWidth="0dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:clickable="true"/>
这篇关于CoordinatorLayout layout_anchor不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文