标签: swiperefreshlayout

向下滚动会触发刷新而不是显示工具栏

我开始使用新的CoordinatorLayout,我遇到了这个问题:

演示

正如您所看到的,当我尝试向下滚动工具栏部分可见时,并且recylcerview位于顶部位置时,它会触发刷新事件而不是拉下工具栏.用户必须再次向上滚动以显示它.

布局XML看起来像这样:activity_main.xml:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                style="@style/customActionBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"/>

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

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:headerLayout="@layout/navigation_drawer_header"
        app:menu="@menu/navigation_items" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

fragment_main.xml:

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:padding="8dp"
            android:scrollbars="none" />

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

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

Ther SwipeRefreshLayout在FrameLayout中,因为我的应用程序中的片段中有更多元素.

任何帮助,将不胜感激.

android swiperefreshlayout android-coordinatorlayout

23
推荐指数
2
解决办法
6975
查看次数

如何使用SwipeRefreshLayout?

背景

Google最近发布了对其支持库的更新,该库现在有一个新的" SwipeRefreshLayout "视图.

该视图允许包装另一个视图,同时支持向下滑动以执行刷新操作.

截图:

在此输入图像描述

问题

谷歌没有提供样本(至少没有我能找到的样本),所以我自己尝试过使用它.

每当我刷卡时,我都会遇到崩溃(NPE),但后来我发现这是因为我没有为它提供"OnRefreshListener".

但我仍然不知道如何使用它,更不用说自定义它了

这是布局文件的XML:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.swiperefreshlayouttest.MainActivity"
    tools:ignore="MergeRootFrame" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TTT"
                android:textSize="40sp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TTT"
                android:textSize="40sp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TTT"
                android:textSize="40sp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TTT"
                android:textSize="40sp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TTT"
                android:textSize="40sp" />
        </LinearLayout>
    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

代码,虽然它根本没有做任何特别的事情:

public class MainActivity extends ActionBarActivity
  {
  @Override
  protected void onCreate(final Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); …
Run Code Online (Sandbox Code Playgroud)

android android-support-library swiperefreshlayout

18
推荐指数
4
解决办法
7万
查看次数

API 21中的SwipeRefreshLayout

我之前使用的是API 19并且正在使用SwipeRefreshLayout我的许多片段.当我第一次加载内容时,我正在使用它setRefreshing(true);并且能够加载内容并且它工作正常.

我在Android 5.0中注意到谷歌正在使用循环进度视图.当我setRefreshing(true);现在打电话时它根本没有效果.无论如何以编程方式显示新的微调器?我已经深入研究了这一点,但无法以编程方式显示它.我已经阅读了以下内容:

http://developer.android.com/tools/support-library/index.html

https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/

SwipeRefreshLayout不显示任何刷新指示

基本上,它没有显示第一次尝试刷新的迹象.

android swiperefreshlayout

18
推荐指数
1
解决办法
6140
查看次数

Android中的SwiperefreshLayout

SwipeRefreshLayout在下面的布局中使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@color/homePageBackground"
  android:orientation="vertical" >


<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout_listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
<fragment
        android:id="@+id/announcementHomefragment"
        android:name="in.test.app.AnnouncementFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/homePageBackground" >

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="15dp"
                android:background="@color/homePageBackground" >

                <TextView
                    android:id="@+id/newsTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:text="@string/new_list"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <fragment
                    android:id="@+id/newshomefragment"
                    android:name="in.test.app.NewsFragment"
                    android:layout_width="wrap_content"
                    android:layout_height="190dp"
                    android:layout_below="@id/newsTitle"
                    android:layout_marginTop="-15dp" />

                <TextView
                    android:id="@+id/productTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/newshomefragment"
                    android:layout_gravity="center"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="5dp"
                    android:gravity="center"
                    android:text="@string/product_in_home"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <fragment
                    android:id="@+id/proCategoryhomefragment"
                    android:name="in.test.app.CategoryFragment"
                    android:layout_width="wrap_content"
                    android:layout_height="170dp" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments uiswipegesturerecognizer swiperefreshlayout

17
推荐指数
3
解决办法
2万
查看次数

Android支持v4 SwipeRefreshLayout空视图问题

为listview设置空视图后,SwipeRefresh无效,这是SwipeRefresh布局的唯一子项.如何解决这个问题?

android android-layout swiperefreshlayout

16
推荐指数
3
解决办法
2万
查看次数

下拉android时,SwipeRefreshLayout加载器不会上升

我已经使用了swipeRefreshLayout和recyclerview,它在所有Android版本中工作正常但在Kitkat中我拉下来然后SwipeRefreshLayout加载器不上升并且也不刷新recyclerview数据但在棒棒糖中工作

我正在使用'com.android.support:support-v4:22.2.1'

编辑1

SwipeRefreshLayout swipe_refresh;
swipe_refresh = (SwipeRefreshLayout)rootView.findViewById(R.id.swipe_refresh);

swipe_refresh.post(new Runnable() {
            @Override
            public void run() {
                swipe_refresh.setRefreshing(true);
            }
        });


swipe_refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                // Loading more data..
                .....
                ....
                getData();

            }
        });

swipe_refresh.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

public void getData(){
    // Load data from web service...
    ...
    ...
    ...


    // After loading
    swipe_refresh.setRefreshing(false);

    // Set data to adapter
}
Run Code Online (Sandbox Code Playgroud)

布局代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@color/grey_100">

     <LinearLayout …
Run Code Online (Sandbox Code Playgroud)

android swiperefreshlayout android-recyclerview

15
推荐指数
1
解决办法
2642
查看次数

无法在swipeRefreshLayout中的ListView中滚动

我遇到了SwipeRefreshLayout的问题.我在布局中有一个列表视图,每次我在列表视图中向上滚动时,滑动刷新布局都会被触发,您永远不能滚动回到布局的顶部.有人有主意吗?

android swipe-gesture swiperefreshlayout

14
推荐指数
1
解决办法
8376
查看次数

SwipeRefreshLayout:滑动进度动画

我对Android很新,我正在谷歌网站上探索示例代码.我目前的代码是SwipeRefreshLayout:http://developer.android.com/samples/SwipeRefreshLayoutBasic/index.html

在代码中,我们看到正在为列表视图执行SwipeRefreshLayout,换句话说,如果向下拖动列表视图,则会触发该方法并且listview将自行刷新.

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

    <ListView
          android:id="@android:id/list"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

让我感到困惑的是,当您向下拖动时,进度动画栏的代码中没有布局显示在列表视图的顶部.你认为SwipeRefreshLayout在你向下拖动时自动生成一个进度动画条而不需要用户在xml中为它指定任何布局吗?

例如,如果想要在进度动画栏的两端放置填充,以便在刷新时动画不会触摸屏幕的末端,那么如何进行操作?

https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html并没有真正说什么.

android listview android-animation swiperefreshlayout

13
推荐指数
2
解决办法
3万
查看次数

工具栏未显示滑动以刷新

我正在尝试使用刷卡实现折叠收费栏刷新和回收查看.当我试图滚动(当recyclerview只有一个项目时)工具栏崩溃,但当我试图向下滚动显示工具栏时,这是不可能的,因为向下滑动会导致滑动刷新.当recyclerview有更多项目时,它完美地运作.

链接到gif有问题

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="1dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="1dp"
        android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />


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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/activity_main_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/cities_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="16dp"
    android:elevation="1dp"
    android:onClick="addCity"
    android:src="@drawable/ic_plus_white_36dp"
    app:borderWidth="0dp" />
Run Code Online (Sandbox Code Playgroud)

android swiperefreshlayout android-recyclerview android-design-library

12
推荐指数
1
解决办法
4626
查看次数

SyncAdapter始终处于挂起状态

我目前正在开发一个Android应用程序,它依赖于SyncAdapter从服务器刷新其内容.我基本上遵循了这些说明:https://developer.android.com/training/sync-adapters/creating-sync-adapter.html

直到最近,这仍然很好.我知道这可能听起来很愚蠢,但老实说我不知道​​我是怎么搞砸的:(


设置

我有一个ContentProvider,因此SyncAdapter我想要同步的所有项目的一个和一个帐户.我使用整数标志来确定哪个项目必须同步:

public static final int EVENTS = 0x1;
public static final int NEWS = 0x2;
public static final int SUBSTITUTIONS = 0x4;
public static final int TEACHERS = 0x8;
public static final int ALL = 0xF;
Run Code Online (Sandbox Code Playgroud)

所以在我看来onPerformSync我有类似的东西:

ArrayList<ContentProviderOperation> batchList = new ArrayList<>();

int which = extras.getInt(SYNC.ARG, SYNC.ALL);
if((which & SYNC.NEWS) == SYNC.NEWS) { syncNews(provider, batchList, syncResult, 0, 1); }
if((which & SYNC.EVENTS) == SYNC.EVENTS) { syncEvents(provider, …
Run Code Online (Sandbox Code Playgroud)

android synchronization android-contentresolver android-syncadapter swiperefreshlayout

12
推荐指数
1
解决办法
1122
查看次数