Xi 张熹
Xi 张熹

Reputation: 11071

Is there a way to disable Android ListView animation?

When we drag a ListView to the end or to the top, we can always drag it a little further and it will show a blank background, then when we release it the ListView will bounce back. It's a default animation effect of ListView.

I would like to disable this animation effect.

Upvotes: 8

Views: 8328

Answers (4)

slott
slott

Reputation: 3335

In your xml add the attribute

android:overScrollMode="never"

Upvotes: 10

user1112061
user1112061

Reputation: 21

For older versions api < 9 consider:

@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
    int action = ev.getAction();


    if (action == MotionEvent.ACTION_MOVE) {
        ev.setAction(MotionEvent.ACTION_CANCEL);
        super.dispatchTouchEvent(ev);
        return true;
    }       

    return super.dispatchTouchEvent(ev);
}

Upvotes: 2

Haphazard
Haphazard

Reputation: 10948

This may work. Create a new class that contains the following.

import android.view.View;

public class OverScrollDisabler
{
    public static void disableOverScroll(View view)
    {
        view.setOverScrollMode(View.OVER_SCROLL_NEVER);
    }
}

Then within your code,

if(Build.VERSION.SDK_INT >= 9)
{
    OverScrollDisabler.disableOverScroll(myView);
}

More details here: http://jasonfry.co.uk/?id=30

Upvotes: 12

Related Questions