簡體   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