【问题标题】:How to display FloatingActionButton above listview?如何在列表视图上方显示 FloatingActionButton?
【发布时间】:2015-08-17 14:28:50
【问题描述】:

我想在我的列表视图上方显示 FloatingActionButton。我在我的 activity_main.xml 中使用此代码:

<android.support.v4.widget.DrawerLayout 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"
    android:id="@+id/drawer_layout"
    tools:context=".MainActivity">



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/main_content"
        android:orientation="vertical"
        >
        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:id="@+id/app_bar"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

            />
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="16dp"
            android:src="@drawable/ic_refresh"
            />






        <!-- List view goes here-->

        <ListView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@color/list_divider"
            android:dividerHeight="1dp"
            android:focusable="false"
            android:listSelector="@drawable/list_row_selector"
            android:id="@+id/listView"></ListView>


    </LinearLayout>




    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/main_drawer"
        android:layout_gravity="start"
        app:menu="@menu/menu_drawer"
        app:itemIconTint="@color/colorAccent"
        app:itemTextColor="@color/colorTextSecondary"
        >

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




</android.support.v4.widget.DrawerLayout>

看起来像:

我希望它出现在列表视图的顶部,直到列表视图完全加载。 另外,如何获得旋转刷新图标?请帮我解决这个问题。

【问题讨论】:

标签: android listview


【解决方案1】:

使用RelativeLayout代替LinearLayout在ListView上方显示fab。

这是一个不错的库,包含许多功能和动画,包括旋转:

https://github.com/shell-software/fab

【讨论】:

  • 你能给我一些代码吗?链接到其他网站不被认为擅长 SO。
  • 所以说得更具体一点,提供更多细节,你想实现什么样的轮换?
  • 我不明白为什么它被否决了。在我看到这篇文章并将我的布局从线性更改为相对之前,我一直在努力解决我的晶圆厂没有显示在我的列表视图顶部的问题。谢谢@anton
【解决方案2】:

一个简单的解决方案是将 ListView 和 FloatingActionButton 组合在一个 RelativeLayout 中。

更好的解决方案是将它们的父布局(在您的情况下是 LinearLayout)更改为 RelativeLayout。但是您需要在子级中使用layout_alignParentTop layout_abovelayout_below 的组合来实现您想要的顺序。

【讨论】:

  • 旋转按钮怎么样?
  • @learner 所以这个按钮只是为了表明ListView正在刷新?
  • 我想要一个旋转的圆圈而不是刷新图标,你也可以用代码编辑你的答案吗?
【解决方案3】:

尝试在列表下方插入填充(我认为您的回收站视图)。 padding 的高度必须与 fab 图标的高度相同。 在 Flutter 中,此解决方案完美运行..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 2021-06-28
    相关资源
    最近更新 更多