【问题标题】:floating action button at bottom right右下角的浮动操作按钮
【发布时间】:2016-03-31 16:16:52
【问题描述】:

我正在使用这个 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>

【问题讨论】:

    标签: android android-layout floating-action-button


    【解决方案1】:

    尝试将您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2019-11-28
      • 2020-01-03
      • 1970-01-01
      • 2020-11-15
      • 2015-06-25
      相关资源
      最近更新 更多