android - 在右下角定位 float 操作按钮

标签 android layout floating-action-button

我在 fragment 中实现了一个 float 操作按钮,将其放置在右下方,源代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">


 <ListView
     android:id="@+id/listtipologie"
     style="@style/Widget.AppCompat.Light.ListView.DropDown"
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="1"
     android:clickable="false"
     android:divider="@null"
     android:dividerHeight="10dp"
     android:focusable="false"
     android:footerDividersEnabled="false"
     android:headerDividersEnabled="false"
     android:padding="10dip"></ListView>

  <android.support.design.widget.FloatingActionButton
     android:id="@+id/submit"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="16dp"
     android:clickable="true"
     android:gravity="right"
     android:layout_alignParentBottom="true"
     android:layout_alignParentEnd="true"
     android:layout_alignParentRight="true"
     android:layout_gravity="end|bottom"
     android:layout_below="@id/listtipologie"
     app:srcCompat="@drawable/submit_icon" />



</LinearLayout>

在android studio上显示如下:

enter image description here

但是当我在手机上运行时, float 操作按钮并没有出现在右下方而是高了一点。 App是这样显示的:

enter image description here

谁能帮帮我? 提前致谢。

最佳答案

使用 FrameLayout 而不是 LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">


 <ListView
     android:id="@+id/listtipologie"
     style="@style/Widget.AppCompat.Light.ListView.DropDown"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clickable="false"
     android:divider="@null"
     android:dividerHeight="10dp"
     android:focusable="false"
     android:footerDividersEnabled="false"
     android:headerDividersEnabled="false"
     android:padding="10dip"></ListView>

  <android.support.design.widget.FloatingActionButton
     android:id="@+id/submit"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_margin="16dp"
     android:clickable="true"
     android:layout_gravity="bottom|right"
     app:srcCompat="@drawable/submit_icon" />

</FrameLayout>

关于android - 在右下角定位 float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46770510/

相关文章:

css - CSS div 布局和 IE7 的问题

android - 如何在 styles.xml 中列出 <item name ="app:fabSize">[value]</item>?

java - 方法无法应用于给定类型必需 : int. 找到:无参数

android - 当按下返回按钮时,启动画面退出并打开身份验证 Activity

java - 文本字段不会填充

android - 0dip layout_height 或 layouth_width 的诀窍是什么?

ios - 如何更改tableCell 的imageView 的frame?

android - 我在android studio中遇到了这个问题。我已经下载了链接中提到的文件,并将其粘贴到哪里

Android:如何更改应用程序的大小: float 操作按钮的 fabSize ="normal"

android - 我无法删除抽屉导航 Activity 中的默认粉红色 FloatingActionButton