android - 如何让 float 按钮停留在布局底部?

标签 android xml android-layout floating-action-button coordinator-layout

我正在使用协调器布局、回收器 View 和 float 按钮。不知何故,fab 按钮不会停留在布局的底部。我希望按钮即使在滚动时也能留在底部。我所知道的是,fab 按钮位于回收站 View 中最后一项的底部位置。

enter image description here

list-activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            tools:listitem="@layout/activity_sample_05borangb_parent"
            android:id="@+id/recyclerView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"/>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:foregroundGravity="bottom"
        android:layout_gravity="bottom|end"/>


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

最佳答案

enter image description here

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"/>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:foregroundGravity="bottom"
        android:layout_margin="16dp"
        android:layout_gravity="bottom|end"/>


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

关于android - 如何让 float 按钮停留在布局底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46065354/

相关文章:

XML 属性验证失败

java - : Lorg/apache/commons/codec/digest/DigestUtils 解析失败

安卓 : to add zoom in text view

php - 来自公共(public)源的 jQuery/PHP 验证

xml - MATLAB:访问 XML 对象

java - 使用 while 循环将多个 LinearLayout 添加到 ScrollView 中

android - 自定义进度对话框动画

android - 如何以编程方式更改 ListView 高度..?

java - 该应用程序在 AVD 上运行良好,但在真实设备上运行不佳

Android 布局设计器在 Eclipse 4.2 中不可用