如何在Android中很长的listview上方为浮动操作按钮设置固定位置? [英] How to set the fixed position for floating action button above very long listview in Android?

查看:92
本文介绍了如何在Android中很长的listview上方为浮动操作按钮设置固定位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个主要与listview一起使用的Android应用.但是我在将Floating Action ButtonLong ListView一起使用时遇到问题.我的问题如下.

I am developing an Android app that is mostly working with listview. But I am having a problem using Floating Action Button together with Long ListView. My problem is as below.

当列表视图只有几个项目时.可以看到Floating item.

When the list view is only has a few item. Floating item can be seen.

这是屏幕截图:

如上所示,仍然可以看到Floating Action Button.但是,当ListView的项目太多并且在屏幕上过多时,将无法看到Floating Action Button.

As you can see above, Floating Action Button is still can be seen.But when ListView has so many items and become excessive to the screen, Floating Action Button cannot been seen.

这是Long Listview

对于第二个屏幕快照,不能再为scrolled down.

For the second screen shot, it cannot be scrolled down any more.

我想要实现的是,我希望浮动底部始终位于Listview上方屏幕的右下方.就像HTMLCSS中的固定位置.

What I want to achieve is, I want the floating bottom always at the bottom right of screen above Listview. Like fixed position in HTML and CSS.

无论Listview有多高,我总是要在这里Floating Action Button

I want Floating Action Button always here no matter how tall the Listview is

这是我的布局文件

<?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>

如何解决我的代码以实现它?

How can I fix my code to achieve it?

推荐答案

尝试使用RelativeLayout而不是LinearLayout.对于FloatingActionButton来说,添加这样的属性,

Try using RelativeLayout instead of LinearLayout. And for FloatingActionButton add attribute like this,

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

这篇关于如何在Android中很长的listview上方为浮动操作按钮设置固定位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆