gallery菜单滑动有一个不好的效果就是每次经过中间的菜单都默认是被选中状态,同时会加载数据 以至于切换不流畅,有一种卡卡的感觉!!其实用线程来处理这个问题,一定的时间后如果选择的index值不变,说明已经稳定不变。废话少说,上部分代码!
//----------------------用到的常量-----------------------------private int showingIndex = -1;private static final int TIME_OUT_DISPLAY =300;private int toShowIndex = 0;//--------------------------------------------------//在选中事件里面做处理public void onItemSelected(AdapterView parent, View v, final int position,long id) {//--------------------------------------------------toShowIndex = position;final Handler handler = new Handler() { @Overridepublic void handleMessage(Message msg) {if(showingIndex != toShowIndex){showingIndex = toShowIndex;menu_position = position;//做你的业务逻辑处理}} };Thread checkChange = new Thread() { @Overridepublic void run() {int myIndex = toShowIndex;try {sleep( TIME_OUT_DISPLAY );if( myIndex == toShowIndex ){handler.sendEmptyMessage(0); }} catch (InterruptedException e) {e.printStackTrace();}} };checkChange.start();}
ok,这样你就可以畅通无阻的滑动你的组件了!!基本上是不会在出现一卡一卡的情况了!