我的活动
下面是布局xml<android.support.design.widget.CoordinatorLayout
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:background="@color/white"
android:fitsSystemWindows="true"
tools:context=".HomeActivity">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.Dark.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.Dark.PopupOverlay">
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:id="@+id/rl_updates"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll_footer"
android:layout_below="@+id/ll_fibres_search">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl_updates"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_all_requirements"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/iron"
android:dividerHeight="1px"/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:onClick="onRequirement"
android:overScrollMode="never"
android:src="@drawable/ic_playlist_add_white_24dp"
app:backgroundTint="@color/pink"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
当我滚动Recycler View时,App Bar就像我想要的那样折叠。但问题是FAB也向下移动了一点。我将16dp边距设置在底部,但它会粘在屏幕的底部。
如何阻止FAB最初向下移动?
答案 0 :(得分:1)
您是否尝试在FloatingActionButton
之外和RelativeLayout
内取得CoordinatorLayout
?你可以这样做并给它属性:
android:layout_gravity="bottom|right|end"
而不是:
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
答案 1 :(得分:0)
为FAB按钮设置锚点
应用程式:layout_anchorGravity =&#34;底部|右|端&#34; 机器人:layout_gravity =&#34;右&#34;
答案 2 :(得分:0)
将RelativeLayout
替换为FrameLayout
,并将此行添加到您的FAB
<强>机器人:layout_gravity = “右|底部”强>
像这样<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl_updates"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_all_requirements"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/iron"
android:dividerHeight="1px"/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:onClick="onRequirement"
android:layout_gravity="right|bottom"
android:overScrollMode="never"
android:src="@drawable/ic_playlist_add_white_24dp"
app:backgroundTint="@color/pink"/>
</FrameLayout>