首页 > 代码库 > ViewFlipper

ViewFlipper

通过viewflipper方法来设置图片的滚动播放

Activity代码

public class MainActivity extends AppCompatActivity {    private ViewFlipper viewFlipper;    public int[]resid={R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher};    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        viewFlipper=(ViewFlipper)findViewById(R.id.viewflipper);        //动态导入的方法加载viewfilpper        for(int i =0;i<resid.length;i++){            viewFlipper.addView(imageView(resid[i]));            //为viewfliper添加动画效果            viewFlipper.setInAnimation(this,R.anim.leftin);            viewFlipper.setOutAnimation(this,R.anim.leftin);            //设定切换的时间间隔            viewFlipper.setFlipInterval(3000);            viewFlipper.startFlipping();        }    }    public ImageView imageView(int resID){        ImageView imageView=new ImageView(this);        imageView.setBackgroundResource(resID);        return imageView;    }}

其中anim.leftin是自定义的动画效果,在之后的课程中会讲到

ViewFlipper