Java:

package com.example.test_ui_thread01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.widget.Button; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//为button1添加一个动画操作
Button button1 = (Button)findViewById(R.id.button1);
TranslateAnimation animation = new TranslateAnimation(0,150,0,0);
animation.setRepeatCount(30);
animation.setDuration(2000);
button1.setAnimation(animation); Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start(); }
});
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test_ui_thread01.MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" /> <Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="97dp"
android:id="@+id/button1" /> <Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_marginTop="81dp"
android:id="@+id/button2" />
</RelativeLayout>

Android笔记之——线程的更多相关文章

  1. android中的线程池学习笔记

    阅读书籍: Android开发艺术探索 Android开发进阶从小工到专家 对线程池原理的简单理解: 创建多个线程并且进行管理,提交的任务会被线程池指派给其中的线程进行执行,通过线程池的统一调度和管理 ...

  2. Android笔记(六):线程及线程通信

    线程 由于Android的Activity中默认所有代码都在主线程(UI线程)中执行,如果在这里面执行耗时任务(例如下载),界面就会无反应且不可操作,直到耗时任务执行完毕. 如果想在执行耗时任务的同时 ...

  3. Android多线程编程<一>Android中启动子线程的方法

          我们知道在Android中,要更新UI只能在UI主线程去更新,而不允许在子线程直接去操作UI,但是很多时候,很多耗时的工作都交给子线程去实现,当子线程执行完这些耗时的工作后,我们希望去修改 ...

  4. Android笔记——Android中数据的存储方式(二)

    我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...

  5. Android ActivityThread(主线程或UI线程)简介

    1. ActivityThread功能 它管理应用进程的主线程的执行(相当于普通Java程序的main入口函数),并根据AMS的要求(通过IApplicationThread接口,AMS为Client ...

  6. Android开发之线程池使用总结

    线程池算是Android开发中非常常用的一个东西了,只要涉及到线程的地方,大多数情况下都会涉及到线程池.Android开发中线程池的使用和Java中线程池的使用基本一致.那么今天我想来总结一下Andr ...

  7. Android笔记:触摸事件的分析与总结----TouchEvent处理机制

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320   ...

  8. Android应用程序线程消息循环模型分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6905587 我们知道,Android应用程序是 ...

  9. 操作系统学习笔记----进程/线程模型----Coursera课程笔记

    操作系统学习笔记----进程/线程模型----Coursera课程笔记 进程/线程模型 0. 概述 0.1 进程模型 多道程序设计 进程的概念.进程控制块 进程状态及转换.进程队列 进程控制----进 ...

随机推荐

  1. java编译后字节码解析

    java编译后字节码解析 参考网摘: https://my.oschina.net/indestiny/blog/194260

  2. CRM 2016 自定义对话框

    项目背景: CRM表单在操作时会有一些提示,或者交互的对话框. 直接 使用js的alert 和  confirm,网格上有些不协调. 以前在项目中使用过jquery 的,但是CRM官方不建议使用jqu ...

  3. Solr整合Ansj中文分词器

    Ansj的使用和相关资料下载参考:http://iamyida.iteye.com/blog/2220833 参考 http://www.cnblogs.com/luxh/p/5016894.html ...

  4. 创建一个List获取数据的lookup

    第一步,在类:syslookup中新建方法 public static client void lookupList(FormStringControl _formStringControl, Lis ...

  5. 集成IC刷卡器经验

    因为一系列的原因,IC刷卡器要渐渐地取代磁条刷卡器.公司在这方面也是需要跟进的,在我负责集成IC刷卡器到应用程序的过程中,积累了些经验,现在分享下. 第一:无论是磁条还是IC刷卡器都是刷卡器的一种,所 ...

  6. 【简洁之美】裴波那切数列生成器 python

    裴波那切数列可以用生成器较好的去生成,直接上代码: # 1 控制最大数字版本 def fib(max): x,y = 0,1 while y < max: yield x x,y = y,x+y ...

  7. (转)ArcGIS制图技巧

    ArcGIS制图技巧(转载自新浪博客)   1  引言 1.1  制图的目的 随着GIS在各行各业的深入应用,各信息化部门和生产单位都逐渐建立起自己的GIS的应用,同时积累了大量的地理数据.随着应用深 ...

  8. iOS项目中安装和使用 Cocoapods

    1.首先我们要打开我们的终端: 2.在终端输入 这条命令  gem sources -l 2.1如果是和我是一样的显示,则镜像已添加,无需更改,如果不一样,则需要进行更改 这里输出的如果是 https ...

  9. shell return value

  10. 进击的docker 二 : docker 快速入门

    1.安装docker 1.1.安装环境 [root@docker ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@docke ...