繁体   English   中英

在右下方定位浮动操作按钮

[英]Positioning floating action button at bottom right

我在片段中实现了一个浮动操作按钮,使用以下源代码将其放在右下角:

<?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上的显示如下:

在此输入图像描述

但是当我在手机上运行时,浮动动作按钮不会出现在右下角,而是会更高一些。 应用程序以这种方式显示:

在此输入图像描述

谁能帮我? 提前致谢。

使用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>

暂无
暂无

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

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