繁体   English   中英

右下角的浮动动作按钮

[英]floating action button at bottom right

我正在使用这个xml,它包含一个ListView和一个浮动动作按钮。 我希望FAB始终位于右下角(但不要太靠近屏幕的边框),但它只适合列表的最后一项(所以当列表中有一个项目时,它就在右上角)

<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.reminder.other_activities.AllSimpleRemindersActivity">

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/simpleRems"
        android:dividerHeight="0dp"
        android:divider="@null"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />

    <RelativeLayout
        android:id="@+id/test"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_margin="10dp"
        android:id="@+id/myFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#FF0000"
        app:borderWidth="0dp"
        app:elevation="8dp"
        app:layout_anchor="@id/test"
        app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

尝试将SwipeMenuListView高度设置为match_parent并删除测试相对布局。

<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.reminder.other_activities.AllSimpleRemindersActivity">

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/simpleRems"
        android:dividerHeight="0dp"
        android:divider="@null"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true" />


    <android.support.design.widget.FloatingActionButton
        android:layout_margin="10dp"
        android:id="@+id/myFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#FF0000"
        app:borderWidth="0dp"
        app:elevation="8dp"
        android:layout_gravity="bottom|right"
        app:layout_anchor="@id/simpleRems"
        app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM