<com.jalen.autobanner.BannerView android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="230dip"> </com.jalen.autobanner.BannerView>
int length = mList.size();
View view = LayoutInflater.from(mContext).inflate(R.layout.banner_view,this,true);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_points);
vp= (ViewPager) view.findViewById(R.id.vp);
ll.removeAllViews();
LinearLayout.LayoutParams ll_parmas = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ll_parmas.leftMargin=5;
ll_parmas.rightMargin=5;
for(int i=0;i<length;i++){
ImageView img = new ImageView(mContext);
img.setLayoutParams(ll_parmas);
if(i==0){
img.setImageResource(R.mipmap.dot_focus);
}else{
img.setImageResource(R.mipmap.dot_blur);
}
ll.addView(img);
mImgs.add(img);
final ImageView imgforview = new ImageView(mContext);
imgforview.setOnClickListener(this);
imgforview.setScaleType(ImageView.ScaleType.FIT_XY);
if(mList.get(i).getType()==0){//本地图片
imgforview.setImageResource(mList.get(i).getDrawableforint());
}else{//网络
Glide.with(mContext).load(mList.get(i).getDrawableforurl()).diskCacheStrategy(DiskCacheStrategy.ALL).into(imgforview);
// Glide.with(mContext).load(mList.get(i).getDrawableforurl()).listener(new RequestListener<String, GlideDrawable>() {
// @Override
// public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// Log.d("yu","Faile:"+e.toString());
// return false;
// }
//
// @Override
// public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
// imgforview.setImageDrawable(resource);
// return false;
// }
// }).into(imgforview);
// Log.d("yu","url: "+mList.get(i).getDrawableforurl());
}
mViews.add(imgforview);
}
vp.setAdapter(new MyAdapter());
vp.addOnPageChangeListener(onPageChange);
private Runnable task = new Runnable() {
@Override
public void run() {
if(isAuto){
currentItem = currentItem%(mViews.size());
// Log.d("yu","runalbe "+currentItem);
if(currentItem==0){
vp.setCurrentItem(currentItem,false);
}else{
vp.setCurrentItem(currentItem);
}
currentItem++;
mHandle.postDelayed(task,delaytime);
}else{
mHandle.postDelayed(task,delaytime);
}
}
};
public void onPageScrollStateChanged(int state) {
switch (state){
case ViewPager.SCROLL_STATE_IDLE://用户什么都没有操作
isAuto=true;
currentItem = vp.getCurrentItem();
// Log.d("yu","IDLE"+currentItem);
// if(vp.getCurrentItem()==mViews.size()){
// vp.setCurrentItem(0,false);
// }
break;
case ViewPager.SCROLL_STATE_DRAGGING://正在滑动
isAuto =false;
break;
case ViewPager.SCROLL_STATE_SETTLING://滑动结束
isAuto=true;
break;
}
}
/** * Indicates that the pager is in an idle, settled state. The current page * is fully in view and no animation is in progress. */ public static final int SCROLL_STATE_IDLE = 0; /** * Indicates that the pager is currently being dragged by the user. */ public static final int SCROLL_STATE_DRAGGING = 1; /** * Indicates that the pager is in the process of settling to a final position. */ public static final int SCROLL_STATE_SETTLING = 2;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有