package com.example.xiaoxiao.view; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.TypedArray; import android.os.Handler; import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.handmark.pulltorefresh.library.internal.Utils; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.List; import adapter.MyPageAdapter; public class BannerView extends ViewPager { public List<String> urls; @SuppressLint("HandlerLeak") private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { int currentItem = getCurrentItem(); currentItem++; setCurrentItem(currentItem); handler.sendEmptyMessageDelayed(0,2000); } }; public void setUrls(List<String> urls) { this.urls = urls; } public BannerView(@NonNull Context context) { super(context); } public BannerView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public void init() { //设置适配器 this.setAdapter(new MyPageAdapter(getContext(),urls)); handler.sendEmptyMessageDelayed(0,2000); } }
自定义轮播图
最新推荐文章于 2024-09-16 10:34:34 发布