代码之家  ›  专栏  ›  技术社区  ›  xxmilcutexx

如何使浮动按钮保持在布局的底部?

  •  2
  • xxmilcutexx  · 技术社区  · 7 年前

    我正在使用 协调器布局

    enter image description here

    列出活动。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>
    
    3 回复  |  直到 7 年前
        1
  •  6
  •   Vidhi Dave    7 年前

    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>
    
        2
  •  3
  •   santosh kumar    7 年前

    你不需要使用android。支持设计小装置。协调布局以实现这种相对布局就足够了。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        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">
    
            <android.support.v7.widget.RecyclerView
                tools:listitem="@layout/activity_sample_05borangb_parent"
                android:id="@+id/recyclerView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical" />
    
        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true" />
    
    </RelativeLayout>
    
        3
  •  2
  •   Ajil O. Vipin Gupta    7 年前

    进行以下更改

    <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"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <RelativeLayout
            android:id="@+id/container"
            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"
            app:fabSize="normal"
            app:layout_anchor="@id/container"
            app:layout_anchorGravity="bottom|end"/>
    
    
    </android.support.design.widget.CoordinatorLayout>
    

    layout_anchor layout_anchorGravity