(四十七)属性动画Demo-创新互联
1、程序结构
武义网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联。2、MainActivity.java程序
package com.example.objectanimator1;
import java.util.ArrayList;
import java.util.List;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private int[] ivId = { R.id.iv_a, R.id.iv_b, R.id.iv_c, R.id.iv_d,
R.id.iv_e, R.id.iv_f, R.id.iv_g, R.id.iv_h };
private List imageInfos = new ArrayList();
private Boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i = 0; i < ivId.length; i++) {
ImageView iv= (ImageView) findViewById(ivId[i]);
imageInfos.add(iv);
iv.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub switch (v.getId()) {
case R.id.iv_a:
if (flag) {
startAnima();
flag= false;
}else {
closeAnima();
flag= true;
}
break;
default:
Toast.makeText(MainActivity.this, "clicked:"+ v.getId() , 0).show();
break;
}
}
private void startAnima() {
// TODO Auto-generated method stub for (int i = 0; i < ivId.length; i++) {
ObjectAnimator oa= ObjectAnimator.ofFloat(imageInfos.get(i),
"translationY", 0, i * 100);
oa.setInterpolator(new BounceInterpolator());
oa.setDuration(1000);
oa.setStartDelay(300);
oa.start();
}
}
private void closeAnima() {
// TODO Auto-generated method stub for (int i = 0; i < ivId.length; i++) {
ObjectAnimator oa= ObjectAnimator.ofFloat(imageInfos.get(i),
"translationY", i * 100, 0);
oa.setInterpolator(new AccelerateInterpolator());
oa.setDuration(1000);
oa.setStartDelay(300);
oa.start();
}
}
}
2、activity_main.xml的代码
网页名称:(四十七)属性动画Demo-创新互联
文章URL:http://azwzsj.com/article/deseeg.html