我正在使用 ListView,其中数据是通过使用适配器从资产文件呈现的。当列表自动滚动时,它不会显示 ListView 的底部子项。但是当它触摸屏幕时,看不见的孩子就会变得可见。我想用自动滚动模式显示它。这是代码
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.list);
loadUrduFileInList();
adapter = new LessonListAdapter(this, R.layout.lesson_list_item, urduDataList);
list.setAdapter(adapter);
list.setOnScrollListener(this);
verticalScrollMax = getListViewHeight(list);
verticalScrollMax = verticalScrollMax - 921;
ViewTreeObserver vto = list.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
list.getViewTreeObserver().removeGlobalOnLayoutListener(this);
verticalScrollMax = getListViewHeight(list);
verticalScrollMax = verticalScrollMax - 921;
startAutoScrolling();
}
});
}
public void startAutoScrolling()
{
if (scrollTimer == null)
{
scrollTimer = new Timer();
final Runnable Timer_Tick = new Runnable()
{
public void run()
{
moveScrollView();
}
};
if (scrollerSchedule != null)
{
scrollerSchedule.cancel();
scrollerSchedule = null;
}
scrollerSchedule = new TimerTask()
{
@Override
public void run()
{
runOnUiThread(Timer_Tick);
}
};
scrollTimer.schedule(scrollerSchedule, 20, 20);
}
}
public void moveScrollView()
{
scrollPos = (int) (list.getScrollY() + 1.0);
if (scrollPos >= verticalScrollMax)
{
scrollPos = 0;
}
list.scrollTo(0, scrollPos);
}