public class MainActivity extends AppCompatActivity { private ViewFlipper flipper; //背景图片int[] id private int[] resID = {R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,R.drawable.pic4}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); flipper = (ViewFlipper) findViewById(R.id.flipper); //动态导入的方式为ViewFlipper加入子View for(int i = 0; i < resID.length ; i++){ flipper.addView(getimageview(resID[i])); } //为ViewFlipper去添加动画效果 flipper.setInAnimation(this,R.anim.right_in); flipper.setOutAnimation(this,R.anim.right_out); //切换间隔时间 flipper.setFlipInterval(3000); //开始播放 flipper.startFlipping(); } private ImageView getimageview(int resID){ ImageView image = new ImageView(this); image.setBackgroundResource(resID); return image; }
时间: 2024-10-13 22:26:44