Android 控制listview 滑动速度

android 因为listview本身的滑动速度太快,我的界面的速度刷新太快,所以视觉上会看不清数据,需要控制listview的滑动速度,找到如下一篇文章:

      大概的意思就是控制listview的滑动速度,可以使用 ViewConfiguration里的一个getScrollFriction摩擦力属性,来增加摩擦系数,从而让滑动变慢,主要是依据:


//摩擦力,用来计算减速度
ViewConfiguration.getScrollFriction()
mDeceleration = computeDeceleration(ViewConfiguration.getScrollFriction());

如下为原文和扩展:

How to control Android ListView scrolling speed

I found that I can control the scrolling speed of an Android ListView using code like this in a Fragment:

@Override
public void onStart() {
    super.onStart();
    // scroll speed decreases as friction increases. a value of 2 worked
    // well in an emulator; i need to test it on a real device
    getListView().setFriction(ViewConfiguration.getScrollFriction() * 2);
}

I did this because the default ListView scroll speed is too fast by default, and as a result, it’s hard on the eyes when you scroll through a lot of items.





简介: ViewConfiguration 是系统中关于视图的各种特性的常量记录对象。其中包含各种基础数据

ViewConfiguration中的值一般是在编写高级控件是才会用到。由于常量非常多,部分常量光看说明无法知道其真实作用,这是一个慢慢收集记录的过程,在实际运用中遇到新的常量我会慢慢添加。

 

//在可滑动的控件中用于区别单击子控件和滑动操作的一个伐值。

mTouchSlop = configuration.getScaledTouchSlop();

//用于设置最小加速率和最大速率
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

 

//滚动距离
mOverscrollDistance = configuration.getScaledOverscrollDistance();

//fling距离
mOverflingDistance = configuration.getScaledOverflingDistance();

 

//摩擦力,用来计算减速度
ViewConfiguration.getScrollFriction()
mDeceleration = computeDeceleration(ViewConfiguration.getScrollFriction());

computeDeceleration 公式

 return SensorManager.GRAVITY_EARTH   // g (m/s^2)
                      * 39.37f               // inch/meter
                      * mPpi                 // pixels per inch
                      * friction;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值