zoukankan      html  css  js  c++  java
  • 新控件思路定义一个线程,当达到执行时间才执行相应事件

    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() {   
    @Override
    public void handleMessage(Message msg) {
    if(showingIndex != toShowIndex){
    showingIndex = toShowIndex;
    menu_position = position;

    //做你的业务逻辑处理
    }
    }   
    };
    Thread checkChange = new Thread() {     
    @Override
    public void run() {
    int myIndex = toShowIndex;
    try {
    sleep( TIME_OUT_DISPLAY );
    if( myIndex == toShowIndex ){
    handler.sendEmptyMessage(0);   
    }
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }   
    };

    checkChange.start();


    }
    ok,这样你就可以畅通无阻的滑动你的组件了!!基本上是不会在出现一卡一卡的情况了!

  • 相关阅读:
    selenium之css selector
    selenium之xpath
    selenium的一些概念
    HTML基础(四)JS
    HTML基础(三)DOM操作
    HTML基础(二)CSS
    HTML基础(一)HTML标签
    python学习笔记(六)发邮件、写日志、操作redis、导入模块
    python学习笔记(五)模块、第三方模块安装、模块导入
    python学习笔记(四)函数(下)、模块、集合
  • 原文地址:https://www.cnblogs.com/pandans/p/1882877.html
Copyright © 2011-2022 走看看