Android(列表)视图像 Sense UI 一样滚动

发布于 2024-11-29 07:31:16 字数 232 浏览 1 评论 0原文

我在 google 和 stackoverflow 上搜索了一段时间,但找不到解决方案。 是否有可能像 sense ui 那样在 Android 2.2 或 2.1 上获得 listview 过度滚动? 就像我的闹钟视图中的那样: AlarmView Sense UI

I've searched some time on google and on stackoverflow but i can't find a solution.
Is there any posibility to get a listview overscroll on Android 2.2 or 2.1 like the sense ui does?!
Like here in my alarm view: AlarmView Sense UI

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不美如何 2024-12-06 07:31:16

看到奇拉格的回答得到如此高的评价,我感到很震惊。它对任何人都没有帮助,因为它不完整并且无法构建。它也没有引用其来源。

原始代码位于:http://code.google.com/p/scroll-pager /

另请注意,滚动分页器代码是在 GPL 许可证下发布的。

更新 :
我与scroll-pager的作者交谈过,他现在已经切换到MIT许可证。

I'm shocked to see Chirag's answer being highly rated like this. It isn't helpful to anyone because its incomplete and doesn't build. It also doesn't cite its source.

The original code is found here: http://code.google.com/p/scroll-pager/

Also note that the scroll-pager code is released under the GPL license.

UPDATE :
I talked to the author of scroll-pager and he has now switched to the MIT license.

层林尽染 2024-12-06 07:31:16

Listview 内置了对过度滚动的支持。查看 setOverscrollMode 及相关方法 setOverscrollHeadersetOverscrollFooter。 ListView 通过覆盖 AbsListView.onOverscrolled;如果您想要不同的行为,您可以通过自己覆盖它来实现它。

Listview has built-in support for overscrolling. Check out setOverscrollMode and related methods setOverscrollHeader and setOverscrollFooter. ListView makes use of the overscroll header/footer by overriding AbsListView.onOverscrolled; if you want different behavior, you can implement it by overriding it yourself.

情深已缘浅 2024-12-06 07:31:16

http://developer.android.com/reference/android/widget/ScrollView.html

您永远不应该将 ScrollView 与 ListView 一起使用,因为 ListView 负责其自己的垂直滚动。最重要的是,这样做会破坏 ListView 中处理大型列表的所有重要优化,因为它有效地强制 ListView 显示其整个项目列表以填充 ScrollView 提供的无限容器。

http://developer.android.com/reference/android/widget/ScrollView.html

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

寄居者 2024-12-06 07:31:16

我可以看到这篇文章已经很老了,但我最近在 GitHub 上发布了这个开源项目 它解决了这个问题,并可以帮助其他人解决未来类似的过度滚动问题。

它基本上为许多核心 Android 可滚动视图提供类似 iOS 的过度滚动效果 - ListView 就是其中之一,并且非常容易应用。

特别是对于列表视图,您只需执行以下操作即可启用它:

ListView listView = ... // For example: (ListView) findViewById(R.id.list_view);
OverScrollDecoratorHelper.setUpOverScroll(listView);

并且要将项目包含在您的项目中,请将其添加到您的 build.gradle 中:

dependencies {
    // ...

    compile 'me.everything:overscroll-decor-android:1.0.0'
}

I can see this post is pretty old, but I've recently released this open-source project on GitHub which solves this problem and could help others solve similar over-scroll issues in the future.

It basically provides an iOS-like over-scrolling effect for many core Android scrollable views - ListView is one of them, and is very easy to apply.

Specifically for list-views, all you have to do to enable it this:

ListView listView = ... // For example: (ListView) findViewById(R.id.list_view);
OverScrollDecoratorHelper.setUpOverScroll(listView);

And to include the project in yours, add this to your build.gradle:

dependencies {
    // ...

    compile 'me.everything:overscroll-decor-android:1.0.0'
}
梦途 2024-12-06 07:31:16

在 xml 文件中定义滚动视图。

然后在你的java文件中写入:

scrollView = (ScrollView) findViewById(R.id.scr);
    contentView = (ViewGroup) findViewById(R.id.r2);
    scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, contentView.getPaddingTop());
        }
    });

并在上面的java文件中添加一个类:

public class ScrollPager implements OnTouchListener
public ScrollPager(ScrollView aScrollView, ViewGroup aContentView)
    {
        mScrollView = aScrollView;
        mContentView = aContentView;
        scroller = new Scroller(mScrollView.getContext(), new OvershootInterpolator());
        task = new Runnable()
        {
            public void run()
            {
                scroller.computeScrollOffset();
                mScrollView.scrollTo(0, scroller.getCurrY());

                if (!scroller.isFinished())
                {
                    mScrollView.post(this);
                }
            }
        };
    }

Define scrollview in your xml file.

Then in your java file wite this:

scrollView = (ScrollView) findViewById(R.id.scr);
    contentView = (ViewGroup) findViewById(R.id.r2);
    scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
    scrollView.post(new Runnable() {
        public void run() {
            scrollView.scrollTo(0, contentView.getPaddingTop());
        }
    });

And Add a class in above java file:

public class ScrollPager implements OnTouchListener
public ScrollPager(ScrollView aScrollView, ViewGroup aContentView)
    {
        mScrollView = aScrollView;
        mContentView = aContentView;
        scroller = new Scroller(mScrollView.getContext(), new OvershootInterpolator());
        task = new Runnable()
        {
            public void run()
            {
                scroller.computeScrollOffset();
                mScrollView.scrollTo(0, scroller.getCurrY());

                if (!scroller.isFinished())
                {
                    mScrollView.post(this);
                }
            }
        };
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文