平台:Android2.1
场景:Eink电子书项目,滑动效果会严重影响屏幕的刷新显示。
时间:2011.8.24
前提:
1.ListView继承与AbsListView,主要实现代码都在AbsListView中。
2.其onTouchEvent()函数,对滑动动作做了设置和响应。原理是根据手指在屏幕上的滑动,计算出移动距离,如果足够,则触发滑动。当滑动时,又根据滑动的快慢,计算出滑动的速度值,并不停的连续响应Action_Move动作,不停的小距离滑动,刷新。最后通过一个滑动优化函数,使得滑动显示出的锯齿感的效果明显减弱。
3.滑动函数为trackMotionScroll(),而且滑动优化函数为mFlingRunnable.start()。
4.具体修改,注释Action_Move中滑动函数,同时计算滑动函数需要的2个参数,得出每次屏幕触动完成后的总值。在Action_Up中,调用trackMotionScroll()(此时传入值为之前Action_Move中计算出的总值),同时将其下面的滑动超出判断部分同时加入到其后面。注释掉滑动优化函数。
修改:
+ /*
+ * my data used for scroll
+ */
+ private int totaldeltaY = 0;
+ private int totalincrementalDeltaY = 0;
// No need to do all this work if we're not going to move anyway
if (incrementalDeltaY != 0) {
- trackMotionScroll(deltaY, incrementalDeltaY);
+ //<BB><AC><B6><AF><BA><AF><CA><FD>
+ // trackMotionScroll(deltaY, incrementalDeltaY);
+ totaldeltaY += deltaY;
+ totalincrementalDeltaY += incrementalDeltaY;
+
+
+
}
- // Check to see if we have bumped into the scroll limit
- View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
- if (motionView != null) {
- // Check if the top of the motion view is where it is
- // supposed to be
- if (motionView.getTop() != mMotionViewNewTop) {
- // We did not scroll the full amount. Treat this essentially like the
- // start of a new touch scroll
- final int motionPosition = findMotionRow(y);
-
- mMotionCorrection = 0;
- motionView = getChildAt(motionPosition - mFirstPosition);
- mMotionViewOriginalTop = motionView.getTop();
- mMotionY = y;
- mMotionPosition = motionPosition;
- }
- }
case TOUCH_MODE_SCROLL:
+
+
+
+
+
+ //<BB><AC><B6><AF><BA><AF><CA><FD>
+ trackMotionScroll(totaldeltaY, totalincrementalDeltaY);
+ //<BB><AC><B6><AF><BA><AF><CA><FD>
+ trackMotionScroll(totaldeltaY, totalincrementalDeltaY);
+
+ // Check to see if we have bumped into the scroll limit
+ View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
+ if (motionView != null) {
+ // Check if the top of the motion view is where it is
+ // supposed to be
+
+
+ if (motionView.getTop() != mMotionViewNewTop) {
+
+
+ // We did not scroll the full amount. Treat this essentially like the
+ // start of a new touch scroll
+
+ final int mmotionPosition = findMotionRow(y);
+
+ mMotionCorrection = 0;
+ motionView = getChildAt(mmotionPosition - mFirstPosition);
+ mMotionViewOriginalTop = motionView.getTop();
+ mMotionY = y;
+ mMotionPosition = mmotionPosition;
+
+ }
+ }
+ totaldeltaY = 0;
+ totalincrementalDeltaY = 0;
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
- mFlingRunnable.start(-initialVelocity);
+ //<BB><AC><B6><AF>Ч<B9><FB><D3>Ż<AF><BA><AF><CA><FD>
+ // mFlingRunnable.start(-initialVelocity);
if (!awakenScrollBars()) {
invalidate();
}
- mMotionViewNewTop = mMotionViewOriginalTop + deltaY;
+ // mMotionViewNewTop = mMotionViewOriginalTop + deltaY;
@@ -2517,11 +2668,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
}
- mMotionViewNewTop = mMotionViewOriginalTop + deltaY;
+ // mMotionViewNewTop = mMotionViewOriginalTop + deltaY;
后话:
刚接触android framework做的第一次改动。当时编译ROM烧录开不了机,连log都不会抓,只会不停的make clean,make。然后祈祷烧录后能够正常开机。
没调试方法,没代码阅读能力,硬着头皮,勉强改了出来。