package com.example.mm.helloworld;import android.os.AsyncTask;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 {    private  Button button_up = null;    private int jj=30;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TranslateAnimation animation=new TranslateAnimation(-100,100,0,0);        animation.setDuration(2000);        animation.setRepeatCount(1000);        Button button_down = (Button) findViewById(R.id.button_down);        button_down.setAnimation(animation);        button_up=(Button) findViewById(R.id.button_up);        button_up.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(final View v) {                new DownloadImageTask().execute();            }        });    }    private class DownloadImageTask extends   AsyncTask<String,Void,Integer>    //AsyncTask    {        protected Integer doInBackground(String... urls)  //跟UI无关的耗时操作,写在线程里面        {            try {                Thread.sleep(5000);            }            catch (InterruptedException e)            {                e.printStackTrace();            }            int sum=10;            return  sum;        }        protected  void  onPostExecute(Integer sum)//跟UI组件相关的操作写在post里面        {            button_up.setText(""+sum);        }    }

更多相关文章

  1. Android:UI更新方法二:View.postInvalidate+Thread+Runnable
  2. Android(安卓)封装的数据库管理操作类
  3. Android手势操作(三)
  4. clock时钟
  5. 多线程下载测试TestDownload
  6. JNI|在子线程中获得JNIEnv|AttachCurrentThread
  7. Glide 下载多张图片
  8. 83 Android(安卓)Handler ProgressBar 进度条
  9. Android文件操作放到listview中

随机推荐

  1. Android(安卓)自定义View的简单应用(1) 雷
  2. [Gradle Retrolambda]Android(安卓)Studi
  3. Android(安卓)API Demos学习 - Notificat
  4. Android:网络:获取XML格式数据
  5. [置顶] android socket nio 聊天实现
  6. 【Android(安卓)Studio】RelativeLayout(
  7. 赵雅智:android发彩信操作
  8. Android控件:ProgressBar使用详解
  9. Android(安卓)Mob ShareSDK分享遇到的坑
  10. Android中如何显示本地HTML