方法就是在当前元素竖坐标超过屏幕高度 *0.8 时,将最下面的挪到最上面去,然后判断,将重复的去掉。
缺点是如果 LISTVIEW 有重复元素,最后一页检索可能会有问题。
分享一下源码:
int index=0;
int scrollnum=0;
int[] location=new int[2];
DisplayMetrics dm = new DisplayMetrics();
this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenHeight =dm.heightPixels;
Log.v("mainActivity","屏幕宽度:"+String.valueOf(screenHeight));
while (index<audiolist.getCount())
{
audio=(TextView)solo.getView("***",scrollnum);
audio.getLocationOnScreen(location);
int y=location[1];
Log.v("mainActivity","第"+String.valueOf(index+1)+"个音频名称是:"+audio.getText().toString());
if (audio.getText().toString().equals(testaudio))
{
testnum=index;
Log.v("mainActivity",""+String.valueOf(index+1)+"");
}
index++;
scrollnum++;
if (y>(float)screenHeight*0.8)
{
String scrtext=audio.getText().toString();
solo.scrollListToLine(audiolist,index-1);
solo.sleep(3000);
scrollnum=0;
String nexttext=null;
while (!scrtext.equals(nexttext))
{
audio=(TextView)solo.getView("****",scrollnum);
nexttext=audio.getText().toString();
scrollnum++;
}
}