package com.csy.a;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ViewFlipper;
public class MainActivity extends Activity {
private ViewFlipper flipper;
private int[] resId = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aaa);
flipper = (ViewFlipper) findViewById(R.id.aa);
*******************************************添加图片*********************************************************
for (int i = 0; i < resId.length; i++) {
flipper.addView(getimageView(resId[i]));
}
***********************************************************************************************************************
flipper.setInAnimation(this, R.anim.left_in);
flipper.setOutAnimation(this,R.anim.left_out);
flipper.setFlipInterval(3000);
flipper.startFlipping();
}
private ImageView getimageView(int resId) {
ImageView image = new ImageView(this);
image.setBackgroundResource(resId);
return image;
}
}
*****************************************************************************************
添加图片那一点为什么要写在方法里呢?直接在flipper.addView()里写图片ID不是更方便么?用for循环遍历数组下标的方式
Ma峰
相关分类