-1

I have a ListView, and I have to implement specific behaviour for it.

When user scrolls up the ListView , which is in initial position:

  1. ListView should move down a bit;
  2. ProgressBar should appear;

Next image shows the result that I want to achieve:

enter image description here

Any suggestions how to do this? Thanks.

hornet2319
  • 379
  • 3
  • 15

3 Answers3

1

"There's a library for that"

another library

I believe this library does what you're looking for.

enter image description here

I got this picture from this question

There are lots of libraries doing similar things like in this video https://www.youtube.com/watch?v=YOYtPF-4RPg

Community
  • 1
  • 1
Cobbles
  • 1,748
  • 17
  • 33
1

You can use SwipeRefreshLayout or other library as suggested in @Cobbles answer.

It is not exactly the view you looking for, but the same feature. The advantage of swipe refresh layout is that is part of android support library and user are used to see it.

sonic
  • 1,894
  • 1
  • 18
  • 22
1

Use SwipeRefreshLayout from support-v4 https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

Wrap the ListView in a SwipeRefreshLayout in xml:

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

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

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

And set the listener in your onCreate():

SwipeRefreshLayout swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(this);

and implement it

@Override 
public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
            swipe.setRefreshing(false);
        }
    }, 5000);
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70