摘要

Android应用程序是通过消息来驱动的,当Android主线程启动时就会在内部创建一个消息队列。然后进入一个无限循环中,轮询是否有新的消息需要处理。如果有新消息就处理新消息。如果没有消息,就进入阻塞状态,直到消息循环被唤醒。
那么在Android系统中,消息处理机制是怎么实现的呢?在程序开发时,我们经常会使用Handler处理Message(消息)。所以可以知道Handler是个消息处理者,Message是消息主体。除此之外还有消息队列和消息轮询两个角色。它们分别是MessageQueue和Looper,MessageQueue就是消息队列,Looper负责轮询消息。

简介

我们已经知道Android的消息机制处理主要由Handler、Message、MessageQueue、Looper四个类的实现来完成。那么它们之间的关系是怎样的?
其中,Message是消息主体,它负责存储消息的各种信息,包括发送消息的Handler对象、消息信息、消息标识等。MessageQueue就是消息队列,在其内部以队列的形式维护一组Message(消息)。Handler负责发送和处理消息。Looper负责轮询消息队列。

Android消息机制原理

创建线程消息队列

在Android应用程序中,消息处理程序运行前首先要创建消息队列(也就是MessageQueue)。在主线程中,通过调用Looper类的静态成员函数prepareMainLooper()来创建消息队列。在其他子线程中,通过调用静态成员函数prepare()来创建。
prepareMainLooper()与prepare()的实现:

  /**
   * Initialize the current thread as a looper, marking it as an
   * application's main looper. The main looper for your application
   * is created by the Android environment, so you should never need
   * to call this function yourself. See also: {@link #prepare()}
   * 用来初始化主线程中的Looper,有Android环境调用,不应该有用户调用.
   */
  public static void prepareMainLooper() {
    prepare(false);
    synchronized (Looper.class) {
      if (sMainLooper != null) {
        throw new IllegalStateException("The main Looper has already been prepared.");
      }
      sMainLooper = myLooper();
    }
  }
  
  public static @Nullable Looper myLooper() {
    return sThreadLocal.get();
  }

   /** Initialize the current thread as a looper.
   * This gives you a chance to create handlers that then reference
   * this looper, before actually starting the loop. Be sure to call
   * {@link #loop()} after calling this method, and end it by calling
   * {@link #quit()}.
   * 交给用户自己调用,通过loop()方法开启消息循环.同时当不需要处理消息时,需要手动调用quit()方法退出循环.
   */
  public static void prepare() {
    prepare(true);
  }

  private static void prepare(boolean quitAllowed) {
    if (sThreadLocal.get() != null) {
      throw new RuntimeException("Only one Looper may be created per thread");
    }
    sThreadLocal.set(new Looper(quitAllowed));
  }

在这两个函数调用的过程中,sThreadLocal变量都有被使用。这个变量是ThreadLocal类型的,用来保存当前线程中的Looper对象。也就是说在Android应用程序中每创建一个消息队列,都有一个并且是唯一 一个与之对应的Looper对象。而且我们可以从源码中看到当对象不唯一时就会抛出异常。

private Looper(boolean quitAllowed) {
    mQueue = new MessageQueue(quitAllowed); //创建消息队列
    mThread = Thread.currentThread();
  }

从上面的源码中可以看到,当Looper对象实例化的过程的同时会创建一个消息队列。

消息循环过程

在消息队列建立完成之后,调用Looper对象的静态成员方法loop()就开始了消息循环。

  /**
   * Run the message queue in this thread. Be sure to call
   * {@link #quit()} to end the loop.
   */
  public static void loop() {
    final Looper me = myLooper();
    if (me == null) {
      throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
    }
    final MessageQueue queue = me.mQueue;

    // Make sure the identity of this thread is that of the local process,
    // and keep track of what that identity token actually is.
    Binder.clearCallingIdentity();
    final long ident = Binder.clearCallingIdentity();

    for (;;) { //开始消息循环
      Message msg = queue.next(); // 在接收消息时有可能阻塞
      if (msg == null) {
        //message为null时,退出消息循环
        return;
      }

      // This must be in a local variable, in case a UI event sets the logger
      final Printer logging = me.mLogging;
      if (logging != null) {...}

      final long slowDispatchThresholdMs = me.mSlowDispatchThresholdMs;

      final long traceTag = me.mTraceTag;
      if (traceTag != 0 && Trace.isTagEnabled(traceTag)) {...}
      final long start = (slowDispatchThresholdMs == 0) ? 0 : SystemClock.uptimeMillis();
      final long end;
      try {
        msg.target.dispatchMessage(msg); //处理消息
        end = (slowDispatchThresholdMs == 0) ? 0 : SystemClock.uptimeMillis();
      } finally {
        if (traceTag != 0) {
          Trace.traceEnd(traceTag);
        }
      }
      if (slowDispatchThresholdMs > 0) {
        final long time = end - start;
        if (time > slowDispatchThresholdMs) {...}
      }

      if (logging != null) {...}

      // Make sure that during the course of dispatching the
      // identity of the thread wasn't corrupted.
      final long newIdent = Binder.clearCallingIdentity();
      if (ident != newIdent) {...}
      msg.recycleUnchecked();
    }
  }

上面的源码就是消息循环的过程,只用调用了loop()方法消息循环才开始起作用。当循环开始时:

  • 获取当前线程的Looper对象,如果为null,抛出异常;
  • 获取消息队列,开始进入消息循环;
  • 从消息队列中获取消息(调用MessageQueue的next()方法),如果为null,结束循环;否则,继续执行;
  • 处理消息,回收消息资源( msg.recycleUnchecked())。

在消息循环过程中,通过MessageQueue的next()方法提供消息,在没有信息时进入睡眠状态,同时处理其他接口。这个过程至关重要,通过next()方法也决定了消息循环是否退出。

 Message next() {
    final long ptr = mPtr; //与native方法相关,当mPtr为0时返回null,退出消息循环
    if (ptr == 0) {
      return null;
    }

    int pendingIdleHandlerCount = -1; // -1 only during first iteration
    int nextPollTimeoutMillis = 0; //0不进入睡眠,-1进入书面
    for (;;) {
      if (nextPollTimeoutMillis != 0) {
        //处理当前线程中待处理的Binder进程间通信请求
        Binder.flushPendingCommands(); 
      }
      //native方法,nextPollTimeoutMillis为-1时进入睡眠状态
      nativePollOnce(ptr, nextPollTimeoutMillis); 
      synchronized (this) {
        final long now = SystemClock.uptimeMillis();
        Message prevMsg = null;
        Message msg = mMessages;
        if (msg != null && msg.target == null) {
          // Stalled by a barrier. Find the next asynchronous message in the queue.
          do {
            prevMsg = msg;
            msg = msg.next;
          } while (msg != null && !msg.isAsynchronous());
        }
        if (msg != null) {
          if (now < msg.when) {
            // Next message is not ready. Set a timeout to wake up when it is ready.
            nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE);
          } else {
            // Got a message.
            mBlocked = false;
            if (prevMsg != null) {
              prevMsg.next = msg.next;
            } else {
              mMessages = msg.next;
            }
            msg.next = null;
            if (DEBUG) Log.v(TAG, "Returning message: "   msg);
            msg.markInUse();
            return msg; //返回消息
          }
        } else {
          // No more messages.
          nextPollTimeoutMillis = -1; //更新到睡眠状态
        }

        // Process the quit message now that all pending messages have been handled.
        //消息循环退出
        if (mQuitting) {
          dispose();
          return null;
        }

        // If first time idle, then get the number of idlers to run.
        // Idle handles only run if the queue is empty or if the first message
        // in the queue (possibly a barrier) is due to be handled in the future.
        if (pendingIdleHandlerCount < 0
            && (mMessages == null || now < mMessages.when)) {
          pendingIdleHandlerCount = mIdleHandlers.size();
        }
        if (pendingIdleHandlerCount <= 0) {
          // No idle handlers to run. Loop and wait some more.
          mBlocked = true;
          continue;
        }

        if (mPendingIdleHandlers == null) {
          mPendingIdleHandlers = new IdleHandler[Math.max(pendingIdleHandlerCount, 4)];
        }
        mPendingIdleHandlers = mIdleHandlers.toArray(mPendingIdleHandlers);
      }

      // Run the idle handlers.
      // We only ever reach this code block during the first iteration.
      //非睡眠状态下处理IdleHandler接口
      for (int i = 0; i < pendingIdleHandlerCount; i  ) {
        final IdleHandler idler = mPendingIdleHandlers[i];
        mPendingIdleHandlers[i] = null; // release the reference to the handler

        boolean keep = false;
        try {
          keep = idler.queueIdle();
        } catch (Throwable t) {
          Log.wtf(TAG, "IdleHandler threw exception", t);
        }

        if (!keep) {
          synchronized (this) {
            mIdleHandlers.remove(idler);
          }
        }
      }

      // Reset the idle handler count to 0 so we do not run them again.
      pendingIdleHandlerCount = 0;

      // While calling an idle handler, a new message could have been delivered
      // so go back and look again for a pending message without waiting.
      nextPollTimeoutMillis = 0;
    }
  }

消息循环退出过程

从上面可以看到loop()方法是一个死循环,只有当MessageQueue的next()方法返回null时才会结束循环。那么MessageQueue的next()方法何时为null呢?
在Looper类中我们看到了两个结束的方法quit()和quitSalely()。两者的区别就是quit()方法直接结束循环,处理掉MessageQueue中所有的消息,而quitSafely()在处理完消息队列中的剩余的非延时消息(延时消息(延迟发送的消息)直接回收)时才退出。这两个方法都调用了MessageQueue的quit()方法。

void quit(boolean safe) {
    if (!mQuitAllowed) {
      throw new IllegalStateException("Main thread not allowed to quit.");
    }

    synchronized (this) {
      if (mQuitting) {
        return;
      }
      mQuitting = true; //设置退出状态

      //处理消息队列中的消息
      if (safe) {
        removeAllFutureMessagesLocked(); //处理掉所有延时消息
      } else {
        removeAllMessagesLocked(); //处理掉所有消息
      }

      // We can assume mPtr != 0 because mQuitting was previously false.
      nativeWake(mPtr); // 唤醒消息循环
    }
  }

处理消息队列中的消息:根据safe标志选择不同的处理方式。

  /**
   * API Level 1
   * 处理掉消息队列中所有的消息
   */
  private void removeAllMessagesLocked() {
    Message p = mMessages;
    while (p != null) {
      Message n = p.next;
      p.recycleUnchecked(); //回收消息资源
      p = n;
    }
    mMessages = null;
  }

  /**
   * API Level 18
   * 处理掉消息队列中所有的延时消息
   */
  private void removeAllFutureMessagesLocked() {
    final long now = SystemClock.uptimeMillis();
    Message p = mMessages;
    if (p != null) {
      if (p.when > now) {
        removeAllMessagesLocked();
      } else {
        Message n;
        for (;;) {
          n = p.next;
          if (n == null) {
            return;
          }
          if (n.when > now) {
            //找出延时消息
            break;
          }
          p = n;
        }
        p.next = null;
        //由于在消息队列中按照消息when(执行时间排序,所以在第一个延时消息后的所有消息都是延时消息)
        do {
          p = n;
          n = p.next;
          p.recycleUnchecked(); //回收消息资源
        } while (n != null);
      }
    }
  }

消息发送过程

在Android应用程序中,通过Handler类向线程的消息队列发送消息。在每个Handler对象中持有一个Looper对象和MessageQueue对象。

public Handler(Callback callback, boolean async) {
    if (FIND_POTENTIAL_LEAKS) {
      final Class<? extends Handler> klass = getClass();
      if ((klass.isAnonymousClass() || klass.isMemberClass() || klass.isLocalClass()) &&
          (klass.getModifiers() & Modifier.STATIC) == 0) {
        Log.w(TAG, "The following Handler class should be static or leaks might occur: "  
          klass.getCanonicalName());
      }
    }

    mLooper = Looper.myLooper(); //获取Looper对象
    if (mLooper == null) {...}
    mQueue = mLooper.mQueue; //获取消息队列
    mCallback = callback;
    mAsynchronous = async;
  }

在Handler类中,我们可以看到多种sendMessage方法,而它们最终都调用了同一个方法sendMessageAtTime()方法。

  public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
    MessageQueue queue = mQueue;
    if (queue == null) {
      RuntimeException e = new RuntimeException(
          this   " sendMessageAtTime() called with no mQueue");
      Log.w("Looper", e.getMessage(), e);
      return false;
    }
    //向消息队列中添加消息
    return enqueueMessage(queue, msg, uptimeMillis); 
  }
  
  private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
    msg.target = this;
    if (mAsynchronous) {
      msg.setAsynchronous(true);
    }
    return queue.enqueueMessage(msg, uptimeMillis);
  }

可以看出这两个方法十分容易理解,就是通过MessageQueue对象调用enqueueMessage()方法向消息队列中添加消息。

boolean enqueueMessage(Message msg, long when) {
    // Handler为null
    if (msg.target == null) {
      throw new IllegalArgumentException("Message must have a target.");
    }
    //消息已经被消费
    if (msg.isInUse()) {
      throw new IllegalStateException(msg   " This message is already in use.");
    }

    synchronized (this) {
      //是否退出
      if (mQuitting) {
        IllegalStateException e = new IllegalStateException(
            msg.target   " sending message to a Handler on a dead thread");
        Log.w(TAG, e.getMessage(), e);
        msg.recycle();
        return false;
      }

      msg.markInUse();
      msg.when = when;
      Message p = mMessages;
      boolean needWake;
      if (p == null || when == 0 || when < p.when) {
        // New head, wake up the event queue if blocked.
        // 队列没有消息,直接加入
        msg.next = p;
        mMessages = msg;
        needWake = mBlocked;
      } else {
        // Inserted within the middle of the queue. Usually we don't have to wake
        // up the event queue unless there is a barrier at the head of the queue
        // and the message is the earliest asynchronous message in the queue.
        needWake = mBlocked && p.target == null && msg.isAsynchronous();
        Message prev;
        for (;;) {
          prev = p;
          p = p.next;
          // 根据执行时间插入到相应位置
          if (p == null || when < p.when) {
            break;
          }
          if (needWake && p.isAsynchronous()) {
            needWake = false;
          }
        }
        msg.next = p; // invariant: p == prev.next
        prev.next = msg;
      }

      // We can assume mPtr != 0 because mQuitting is false.
      if (needWake) {
        nativeWake(mPtr); //唤醒消息循环
      }
    }
    return true;
  }

从源码可以看出,一个消息插入到消息队列中需要以下步骤:

消息持有的Handler对象为null,抛出异常;当消息已经被消费,抛出异常;
当消息队列没有消息时,直接插入;
当消息队列存在消息时,通过比较消息的执行时间,将消息插入到相应的位置;
判断是否需要唤醒消息循环。

消息处理过程

在消息循环过程中,如果有新的消息加入,就开始处理消息。从上面的分析中,我们可以看到在消息循环中,目标消息会调用其Handler对象的dispatchMessage()方法,这个就是处理消息的方法。

 /**
   * Handle system messages here.
   */
  public void dispatchMessage(Message msg) {
    // 消息Callback接口不为null,执行Callback接口
    if (msg.callback != null) {
      handleCallback(msg);
    } else {
      if (mCallback != null) {
        //Handler Callback接口不为null,执行接口方法
        if (mCallback.handleMessage(msg)) {
          return;
        }
      }
      handleMessage(msg); //处理消息
    }
  }

从源码可以看出,Handler处理消息分为3中情况。

  1. 当Message中的callback不为null时,执行Message中的callback中的方法。这个callback时一个Runnable接口。
  2. 当Handler中的Callback接口不为null时,执行Callback接口中的方法。
  3. 直接执行Handler中的handleMessage()方法。

当Looper开始调用loop()时主线程为什么不会卡死

在进行完上面的分析后,我们都知道Looper.loop()进入到了一个死循环,那么在主线程中执行这个死循环为什么没有造成主线程卡死或者说在主线程中的其他操作还可以顺利的进行,比如说UI操作。因为Android应用程序是通过消息驱动的,所以Android应用程序的操作也是通过Android的消息机制来实现的。这个时候就需要分析一下Android程序启动的入口类ActivityThread。我们都知道当Android程序启动时在Java层就是以ActivityThread的main()方法为入口的,这也就是我们所说的主线程。

public static void main(String[] args) {
    ...
    ...
    ...
    Looper.prepareMainLooper();

    ActivityThread thread = new ActivityThread();
    thread.attach(false); //建立Binder通道 (创建新线程),与ActivityManagerService建立链接

    if (sMainThreadHandler == null) {
      sMainThreadHandler = thread.getHandler();
    }
    ...
    ...
    ...
    Looper.loop();

    throw new RuntimeException("Main thread loop unexpectedly exited");
  }

从ActivityThread的main()方法中我们可以看到Looper的初始化以及消息循环的开始,同时还有一个关键的方法attach()与ActivityManagerService建立链接,这里建立链接是为了之后相应Activity中各种事件的发生。讲到这里还涉及到Native层Looper的初始化,在Looper初始化时会建立一个管道来维护消息队列的读写并通过epoll机制监听读写事件(一种IO多路复用机制)。

  • 当没有新消息需要处理时,主线程就会阻塞在管道上,直到有新的消息需要处理;
  • 当其他线程有消息发送到消息队列时会通过管道来写数据;

在我们调试程序时,我们通过函数的调用栈就可以发现其中的道理:

这也印证了开始的那句话——Android应用程序是通过消息来驱动的。

是否所有的消息都会在指定时间开始执行

这个问题的意思是当我们像消息队列中发送消息时(比如延时1000ms执行一个消息postDelay(action, 1000)),是不是会在1000ms后去执行这个消息。
答案是不一定。我们只Android的消息是按照时间顺序保存在消息队列中的,如果我们向队列中添加多个消息,比如10000个延时1000ms执行的消息,那么其实最后一个执行的消息和第一个执行的消息的执行时间是不一样的。

总结

至此Android系统的消息处理机制就分析完毕了。在Android应用程序中消息处理主要分为3个过程:

  1. 启动Looper中的消息循环,开始监听消息队列。
  2. 通过Handler发送消息到消息队列。
  3. 通过消息循环调用Handler对象处理新加入的消息。

在使用消息队列时,主线程中在程序启动时就会创建消息队列,所以我们使用主线程中的消息机制时,不需要初始化消息循环和消息队列。在子线程中我们需要初始化消息队列,并且注意在不需要使用消息队列时,应该及时调用Looper的quit或者quitSafely方法关闭消息循环,否则子线程可能一直处于等待状态。

以上就是详解Android 消息处理机制的详细内容,更多关于Android 消息处理机制的资料请关注Devmax其它相关文章!

详解Android 消息处理机制的更多相关文章

  1. html5 canvas合成海报所遇问题及解决方案总结

    这篇文章主要介绍了html5 canvas合成海报所遇问题及解决方案总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  2. Html5 video标签视频的最佳实践

    这篇文章主要介绍了Html5 video标签视频的最佳实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  3. HTML5在微信内置浏览器下右上角菜单的调整字体导致页面显示错乱的问题

    HTML5在微信内置浏览器下,在右上角菜单的调整字体导致页面显示错乱的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

  4. ios – containerURLForSecurityApplicationGroupIdentifier:在iPhone和Watch模拟器上给出不同的结果

    我使用默认的XCode模板创建了一个WatchKit应用程序.我向iOSTarget,WatchkitAppTarget和WatchkitAppExtensionTarget添加了应用程序组权利.(这是应用程序组名称:group.com.lombax.fiveminutes)然后,我尝试使用iOSApp和WatchKitExtension访问共享文件夹URL:延期:iOS应用:但是,测试NSURL

  5. Ionic – Splash Screen适用于iOS,但不适用于Android

    我有一个离子应用程序,其中使用CLI命令离子资源生成的启动画面和图标iOS版本与正在渲染的启动画面完美配合,但在Android版本中,只有在加载应用程序时才会显示白屏.我检查了config.xml文件,所有路径看起来都是正确的,生成的图像出现在相应的文件夹中.(我使用了splash.psd模板来生成它们.我错过了什么?这是config.xml文件供参考,我觉得我在这里做错了–解决方法在config.xml中添加以下键:它对我有用!

  6. ios – 无法启动iPhone模拟器

    /Library/Developer/CoreSimulator/Devices/530A44CB-5978-4926-9E91-E9DBD5BFB105/data/Containers/Bundle/Application/07612A5C-659D-4C04-ACD3-D211D2830E17/ProductName.app/ProductName然后,如果您在Xcode构建设置中选择标准体系结构并再次构建和运行,则会产生以下结果:dyld:lazysymbolbindingFailed:Symbol

  7. Xamarin iOS图像在Grid内部重叠

    heyo,所以在Xamarin我有一个使用并在其中包含一对,所有这些都包含在内.这在Xamarin.Android中看起来完全没问题,但是在Xamarin.iOS中,图像与标签重叠.我不确定它的区别是什么–为什么它在Xamarin.Android中看起来不错但在iOS中它的全部都不稳定?

  8. 在iOS上向后播放HTML5视频

    我试图在iPad上反向播放HTML5视频.HTML5元素包括一个名为playbackRate的属性,它允许以更快或更慢的速率或相反的方式播放视频.根据Apple’sdocumentation,iOS不支持此属性.通过每秒多次设置currentTime属性,可以反复播放,而无需使用playbackRate.这种方法适用于桌面Safari,但似乎在iOS设备上的搜索限制为每秒1次更新–在我的情况下太慢了.有没有办法在iOS设备上向后播放HTML5视频?解决方法iOS6Safari现在支持playbackRat

  9. 使用 Swift 语言编写 Android 应用入门

    Swift标准库可以编译安卓armv7的内核,这使得可以在安卓移动设备上执行Swift语句代码。做梦,虽然Swift编译器可以胜任在安卓设备上编译Swift代码并运行。这需要的不仅仅是用Swift标准库编写一个APP,更多的是你需要一些框架来搭建你的应用用户界面,以上这些Swift标准库不能提供。简单来说,构建在安卓设备上使用的Swiftstdlib需要libiconv和libicu。通过命令行执行以下命令:gitclonegit@github.com:SwiftAndroid/libiconv-libi

  10. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

随机推荐

  1. Flutter 网络请求框架封装详解

    这篇文章主要介绍了Flutter 网络请求框架封装详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  2. Android单选按钮RadioButton的使用详解

    今天小编就为大家分享一篇关于Android单选按钮RadioButton的使用详解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

  3. 解决android studio 打包发现generate signed apk 消失不见问题

    这篇文章主要介绍了解决android studio 打包发现generate signed apk 消失不见问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

  4. Android 实现自定义圆形listview功能的实例代码

    这篇文章主要介绍了Android 实现自定义圆形listview功能的实例代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  5. 详解Android studio 动态fragment的用法

    这篇文章主要介绍了Android studio 动态fragment的用法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  6. Android用RecyclerView实现图标拖拽排序以及增删管理

    这篇文章主要介绍了Android用RecyclerView实现图标拖拽排序以及增删管理的方法,帮助大家更好的理解和学习使用Android,感兴趣的朋友可以了解下

  7. Android notifyDataSetChanged() 动态更新ListView案例详解

    这篇文章主要介绍了Android notifyDataSetChanged() 动态更新ListView案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下

  8. Android自定义View实现弹幕效果

    这篇文章主要为大家详细介绍了Android自定义View实现弹幕效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  9. Android自定义View实现跟随手指移动

    这篇文章主要为大家详细介绍了Android自定义View实现跟随手指移动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. Android实现多点触摸操作

    这篇文章主要介绍了Android实现多点触摸操作,实现图片的放大、缩小和旋转等处理,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

返回
顶部