全屏播放,轮播,补间动画
程序员文章站
2022-04-01 19:41:42
//handler方法private int pos = 0; Handler handler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { super.handleMessage(msg); vwv.setCurrentItem(pos); if (msg.what == arr.siz...
//handler方法
private int pos = 0;
Handler handler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
vwv.setCurrentItem(pos);
if (msg.what == arr.size()){
//无限循环
// pos = -1;
//循环一遍跳转
timerTask.cancel();
startActivity(new Intent(MainActivity.this,BannerActivity.class));
}
}
};
//系统给的initView方法
private void initView() {
vwv = (ViewPager) findViewById(R.id.vwv);
timer = new Timer();
}
//运行
@Override
protected void onResume() {
super.onResume();
initTimer();
}
//自己创建的方法
private void initTimer() {
timerTask = new TimerTask() {
@Override
public void run() {
pos++;
handler.sendEmptyMessage(pos);
}
};
//延迟一秒,每一秒执行一次
timer.schedule(timerTask,1000,1000);
}
//停止
@Override
protected void onStop() {
super.onStop();
timer.cancel();
timerTask.cancel();
}
//适配器里的两个手写的方法
@NonNull
@Override
//insta
public Object instantiateItem(@NonNull ViewGroup container, int position) {
//加载布局
View view = LayoutInflater.from(context).inflate(R.layout.layout_item_first, null);
ImageView iv_img = view.findViewById(R.id.iv_img);
//赋值
Integer image = arr.get(position);
iv_img.setImageResource(image);
//添加到容器
container.addView(view);
//返回加载布局
return view;
}
//dest
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
轮播:
//轮播图设置各种功能
//设置标题
ArrayList<String> titles = new ArrayList<>();
titles.add("图片1");
titles.add("图片2");
titles.add("图片3");
//附加功能
//设置标题样式
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
//设置标题动画
banner.setBannerAnimation(Transformer.DepthPage);
//设置轮播时间
banner.setDelayTime(1500);
//设置指示器位置
banner.setIndicatorGravity(BannerConfig.RIGHT);
//设置是否自动播放
banner.isAutoPlay(true);
//设置标题集合
banner.setBannerTitles(titles);
//设置图片集
banner.setImages(arr);
//设置图片加载器
banner.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
// Glide.with(上下文).load(路径).into(图片视图);
Glide.with(context).load(path).into(imageView);
}
});
//开启播放
banner.start();
private void set() {
//透明
AlphaAnimation animation = new AlphaAnimation(1, 0);
//平移
TranslateAnimation animation1 = new TranslateAnimation(0, 150, 0, 300);
//旋转
RotateAnimation animation2 = new RotateAnimation(0, 60);
//变大变小,变小小数后面加f
ScaleAnimation animation3 = new ScaleAnimation(1, 2, 1, 2);
//创建set集合
AnimationSet set = new AnimationSet(this, null);
//透明
set.addAnimation(animation);
//平移
set.addAnimation(animation1);
//旋转
set.addAnimation(animation2);
//变大
set.addAnimation(animation3);
//循环次数,-1是无限循环
set.setRepeatCount(-1);
//设置时间
set.setDuration(2000);
iv_a.startAnimation(set);
}
本文地址:https://blog.csdn.net/kc527347568/article/details/108851358