您的位置:首页 > 移动开发 > Android开发

Android 控制listview 滑动速度

2016-05-20 11:20 1026 查看


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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android listview