在Android中制作一个d跳ListView

在Android中制作一个d跳ListView,第1张

概述我想让我的listview“反d”.为了解释自己,我希望ListView具有与iOs List View对象相同的行为.在列表的顶部和底部,用户可以通过滑动手指来查看列表. 这种行为存在于Android 2.2三星设备上(例如Galaxy Tab GT1000). 在我测试的大多数设备上,列表现在在滚动时表现不同,它会显示一条蓝线,当您再次滑动手指时会变得更亮. 我找到了像这样的BounceLis 我想让我的ListvIEw“反d”.为了解释自己,我希望ListVIEw具有与iOs List VIEw对象相同的行为.在列表的顶部和底部,用户可以通过滑动手指来查看列表.

这种行为存在于Android 2.2三星设备上(例如galaxy Tab GT1000).

在我测试的大多数设备上,列表现在在滚动时表现不同,它会显示一条蓝线,当您再次滑动手指时会变得更亮.

我找到了像这样的BounceListVIEw:

public class BounceListVIEw extends ListVIEw{    private static final int MAX_Y_OVERSCRolL_disTANCE = 200;    private Context mContext;    private int mMaxYOverscrolldistance;    public BounceListVIEw(Context context)     {        super(context);        mContext = context;        initBounceListVIEw();    }    public BounceListVIEw(Context context,AttributeSet attrs)     {        super(context,attrs);        mContext = context;        initBounceListVIEw();    }    public BounceListVIEw(Context context,AttributeSet attrs,int defStyle)     {        super(context,attrs,defStyle);        mContext = context;        initBounceListVIEw();    }    private voID initBounceListVIEw()    {        //get the density of the screen and do some maths with it on the max overscroll distance        //variable so that you get similar behaviors no matter what the screen size        final displayMetrics metrics = mContext.getResources().getdisplayMetrics();            final float density = metrics.density;        mMaxYOverscrolldistance = (int) (density * MAX_Y_OVERSCRolL_disTANCE);    }    @OverrIDe    protected boolean overScrollBy(int deltaX,int deltaY,int scrollX,int scrollY,int scrollRangeX,int scrollRangeY,int maxOverScrollX,int maxOverScrollY,boolean istouchEvent)     {         //This is where the magic happens,we have replaced the incoming maxOverScrollY with our own custom variable mMaxYOverscrolldistance;         return super.overScrollBy(deltaX,deltaY,scrollX,scrollY,scrollRangeX,scrollRangeY,maxOverScrollX,mMaxYOverscrolldistance,istouchEvent);      }}

但是这个ListVIEw的问题在于滚动列表后它不会返回到第一个项目或最后一个项目…它会保留在未填充列表的位置.

有人有想法让它工作吗?

提前致谢!

解决方法 您应该覆盖onOverScrolled,调用它来表示列表已经滚动,并在该函数中使用smoothScrollToposition将ListVIEw滚动回到您想要的位置.

它看起来像:

@OverrIDeprotected voID onOverScrolled(int scrollX,boolean clampedX,boolean clampedY) {    if(scrollY < 0) {        smoothScrollToposition(0);    } else if(scrollY > MAX_SCRolL) {        smoothScrollToposition(getAdapter().getCount());    }}

MAX_SCRolL必须由您使用列表项的高度和适配器中的项目数来确定,尽管看起来您已经在问题中找到了它,所以它应该不是问题.

总结

以上是内存溢出为你收集整理的在Android中制作一个d跳ListView全部内容,希望文章能够帮你解决在Android中制作一个d跳ListView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1127199.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存