【问题标题】:SwipeRefresh with ScrollView and FloatingActionButtonSwipeRefresh 与 ScrollView 和 FloatingActionButton
【发布时间】:2015-02-15 21:44:30
【问题描述】:

我正在尝试使用三个 TableLayout 为浮动按钮和滚动视图实现 SwipeRefreshLayout。我想一直在屏幕上显示浮动按钮(就像它在带有 Material Design 的 Gmail 应用程序上一样)。不幸的是,滑动刷新阻止了向上滚动。如何通知滑动刷新我的滚动视图要向上滚动?我应该改变布局结构吗?

我正在使用库https://github.com/futuresimple/android-floating-action-button

这是我的布局:

<android.support.v4.widget.SwipeRefreshLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/scroll_recent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TableLayout
                android:id="@+id/table_recent_claims"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TableLayout>

            <TableLayout
                android:id="@+id/table_recent_rapidscans"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TableLayout>

            <TableLayout
                android:id="@+id/table_recent_journeys"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TableLayout>
        </LinearLayout>
    </ScrollView>

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        fab:fab_icon="@drawable/fab_plus24" />
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>

【问题讨论】:

    标签: android swiperefreshlayout floating-action-button


    【解决方案1】:

    您需要以编程方式为您的SwipeRefreshLayout 覆盖canChildScrollUp() 方法。每种情况都不同,具体取决于您在SwipreRefreshLayout 下拥有的子视图。

    另外,我认为 FrameLayout 在您的情况下是不必要的,并且可能会拦截 ScrollView 的可滚动性

    Google 提供了一些可用于正确实现SwipeRefreshLayout 的资源和代码示例:

    一个视图:https://developer.android.com/samples/SwipeRefreshListFragment/index.html

    多个视图:https://developer.android.com/samples/SwipeRefreshMultipleViews/index.html

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 2014-04-01
      • 2016-09-23
      • 2015-11-30
      • 2017-03-19
      • 1970-01-01
      • 2015-11-13
      • 2020-12-07
      • 2015-08-18
      相关资源
      最近更新 更多