我有 15-20 张全屏图像,我正试图在 listview 中一张一张地加载它们。我能够做到这一点,但我的问题是,当我试图滚动到下一个项目时,就像跳到下一个项目不平滑滚动下面是我的代码,请建议我做错了什么。
mArticleContainer.setOnScrollListener(new OnScrollListener() {
int i = 0;
int Pre = 0;
int NumberOfPages = 0;
boolean touchstate = false;
@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {
arg0.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent ev) {
Log.i("MAgazineDetailActivity", "list touch activated");
String s = ev.getAction() + "";
if (s.equalsIgnoreCase("1")) {
touchstate = false;
int a = (int) ev.getY();
if (Pre > a) {
i++;
if (i >= NumberOfPages) {
i = NumberOfPages - 1;
}
Log.e("Message---", "" + i + " Pre---" + Pre);
mArticleContainer.setSelection(i);
// removeView(i - 1);
} else if (Pre < ev.getY()) {
// i--;
if (i < 0)
i = 0;
Log.e("Message", "" + i + " Pre---" + Pre);
// removeView(i + 1);
mArticleContainer.setSelection(i);
} else
mArticleContainer.setSelection(i);
ev.setAction(MotionEvent.ACTION_CANCEL);
return false;
} else if (s.equalsIgnoreCase("2")) {
if (!touchstate) {
Pre = (int) ev.getY();
touchstate = true;
}
} else if (s.equalsIgnoreCase("0")) {
}
return false;
}
});
}
@Override
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
i = arg1;
NumberOfPages = arg3;
}
});
谢谢..