========================代码一========================
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anim);
dotImg = (ImageView) findViewById(R.id.anim_dotimg);
btn = (Button) findViewById(R.id.anim_btn);
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
AlphaAnimation alphaAnim = new AlphaAnimation(0.5f, 1f);
alphaAnim.setDuration(2000);
dotImg.setAnimation(alphaAnim);
alphaAnim.start();
Log.d("test", "start anim");
}
});
}
========================代码一========================
========================代码二========================
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anim);
dotImg = (ImageView) findViewById(R.id.anim_dotimg);
btn = (Button) findViewById(R.id.anim_btn);
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
AlphaAnimation alphaAnim = new AlphaAnimation(0.5f, 1f);
alphaAnim.setDuration(2000);
dotImg.startAnimation(alphaAnim);
Log.d("test", "start anim");
}
});
}
========================代码二========================
Q1:为何代码一动画无效果?或者说不执行?
Q2:有些文章说,更新UI必须在UI主线程。那么请问一些事件,如Click、Destroy等,我如何分辨哪些事件并不是UI主线程在执行呢?
1
kcworms 2015-06-16 11:28:22 +08:00
1.动画没有应用到View上
2.只要自己不采取任何手段开新线程,都是在UI线程(不确定,求指出例外) |
2
hahasong 2015-06-16 11:31:29 +08:00
Q1:动画官方建议是用 ValueAnimator 及其子类
Q2:所有在 Activity主线程上执行的代码都属于UI线程,另起的Thread, HandleThread, AscyTask 上执行的代码属于后台线程 |