如何在Android中设置超长listview上方浮动操作按钮的固定位置?

如何在Android中设置超长listview上方浮动操作按钮的固定位置?,android,listview,floating-action-button,Android,Listview,Floating Action Button,我正在开发一个Android应用程序,它主要与listview一起工作。但是我在使用浮动操作按钮和长列表视图时遇到问题。我的问题如下 当列表视图为时,只有少数项浮动项 这是屏幕截图: 正如您在上面所看到的,浮动操作按钮仍然可以看到。但是当列表视图中的项目太多并且超出屏幕时,浮动操作按钮无法看到 这是长列表视图的屏幕截图 对于第二个屏幕截图,它不能再向下滚动了 我想要实现的是,我希望浮动底部始终位于列表视图上方屏幕的右下角。类似于HTML和CSS中的固定位置 我希望浮动操作按钮始终在这里,无论

我正在开发一个Android应用程序,它主要与
listview
一起工作。但是我在使用
浮动操作按钮
长列表视图
时遇到问题。我的问题如下

当列表视图为时,只有少数项<可以看到代码>浮动项

这是屏幕截图:

正如您在上面所看到的,
浮动操作按钮
仍然可以看到。但是当
列表视图
中的项目太多并且超出屏幕时,
浮动操作按钮
无法看到

这是
长列表视图的屏幕截图

对于第二个屏幕截图,它不能再向下滚动了

我想要实现的是,我希望浮动底部始终位于
列表视图上方屏幕的右下角。类似于
HTML
CSS
中的固定位置

我希望
浮动操作按钮始终在这里,无论
列表视图有多高

这是我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
        <ListView
            android:dividerHeight="@dimen/list_item_divider_height"
            android:padding="@dimen/list_padding"
            android:divider="@color/whitesmoke"
            android:id="@+id/listview_podcast_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></ListView>

        <TextView
            android:textSize="17dp"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:textAlignment="center"
            android:id="@+id/tf_no_records"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/stop_podcast_button"
        android:background="@color/colorPrimary"
        android:src="@android:drawable/ic_dialog_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"/>
</LinearLayout>


如何修复代码以实现它?

尝试使用RelativeLayout而不是LinearLayout。对于FloatingActionButton,添加如下属性

    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="end|bottom"

不要将按钮放置在线性布局中

使用


框架布局以便您可以将视图置于其他视图之上

尝试使用协调布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="listview.anubavam.com.listview.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" >

        </android.support.v7.widget.Toolbar>


    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_menu_camera" />

</android.support.design.widget.CoordinatorLayout>


你是爱的兄弟:-*是否需要
android:layout\u alignParentEnd=“true”
android:layout\u alignParentRight=“true”
?当
LinearLayout
ParentEnd
不匹配
ParentRight