微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > 在android4.1及之后版本如何恢复ListView/GridView下拉空白回弹的效果

在android4.1及之后版本如何恢复ListView/GridView下拉空白回弹的效果

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]
在android 4.0及以前的版本,mtk有在Google默认模糊边缘的基础上,做了一个下拉回弹的效果:在ListView和GridView等列表控件的界面上,当滑动画面到顶部或底部时,屏幕上方或下方处会有一个很长的空的区域,松手以后列表会自动弹回。但是android4.1及之后版本无此效果,因为这个效果会引起CTS test fail!
如果不需要通过CTS测试,请问如何恢复ListView/GridView下拉空白回弹的效果?
效果图:



[SOLUTION]
1.请修改alps/php?mod=tag&id=6090" target="_blank" class="relatedlink">Frameworks/base/core/java/android/view/ViewConfiguration.java
修改如下两个变量:
/**
* Max distance to overscroll for edge effects
*/
private static final int OVERSCROLL_DISTANCE = 240; //将0改为240
/**
* Max distance to overfling for edge effects
*/
private static final int OVERFLING_DISTANCE = 240; //将6改为240
2.请修改alps/frameworks/base/core/java/android/widget/AbsListView.java,找到
FlingRunnable这个类的run()方法,找到其中的
private class FlingRunnable implements Runnable {
...
@Override
public void run() {
...
case touch_MODE_OVERFLING: {
final OverScroller scroller = mScroller;
if (scroller.computeScrollOffset()) {
final int scrollY = mScrollY;
final int currY = scroller.getCurrY();
final int deltaY = currY - scrollY; /// 刪掉這行
/// 新增下面的代碼
/**
* M: If user flings on the list in an opposite direction during an over fling quickly,
* the scrollY will change fROM positive(negative) to negative(positive), so list
* run into abnormal state, view will be not displayed(only mScrollY changes).
*
* To fix this, we only let the list scroll by mScrollY distance to make the list
* restore the normal touch state, then fling the list using the current velocity. @{
*/
final int deltaY;
final boolean needChangeMode = ((mScrollY >= 0 && currY <= 0) || (mScrollY <= 0 &&
currY >= 0));
if (needChangeMode) {
deltaY = -mScrollY;
} else {
deltaY = currY - scrollY;
}
/** @} */
if (overScrollBy(0, deltaY, 0, scrollY, 0, 0,
0, mOverflingDistance, false))
......
......
} else {
Xlog.d(TAG, "FlingRunnable overfling intend to endfling: mScrollY = "+
mScrollY);
if(mScrollY !=0){ //mtk add
if(sDbgMotion) Log.d(TAG,"FlingRunnable TOUCH_MODE_OVERFLING,mScroller
animation fininshed,mScrollY !=0,will startSpringBack");
startSpringback(); //mtk add
}else{ //mtk add
endFling();
} //mtk add
}
break;
标注//mtk add的代码为新增代码
再次提醒,这个改动会导致CTS 测试AbsListViewTest.java中testSetOnScrollListener()这个test
case 测试失败,如果要过CTS,那务必不要做此FAQ的修改

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top