w View(this);
point.setBackgroundResource(R.drawable.point_normal);// 设置引导页默认圆点
point.setPadding(5, 5, 5, 5);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
10, 10);
if (i > 0) {
params.leftMargin = 10;// 设置圆点间隔
}
point.setLayoutParams(params);// 设置圆点的大小
llPointGroup.addView(point);// 将圆点添加给线性布局
}
// 获取视图树, 对layout结束事件进行监听
llPointGroup.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
// 当layout执行结束后回调此方法
@Override
public void onGlobalLayout() {
System.out.println("layout 结束");
llPointGroup.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
mPointWidth = llPointGroup.getChildAt(1).getLeft()
- llPointGroup.getChildAt(0).getLeft();
System.out.println("圆点距离:" + mPointWidth);
}
});
}
/**
* 触摸监听 当按下时不进行轮播
*
* @author Administrator
*
*/
class NewTouchListener implements OnTouchListener {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
System.out.println("按下了");
mhandler.removeCallbacksAndMessages(null);
break;
case MotionEvent.ACTION_CANCEL:
System.out.println("事件取消");
mhandler.sendEmptyMessageDelayed(0, 3000);
break;
case MotionEvent.ACTION_UP:
System.out.println("抬起");
mhandler.sendEmptyMessageDelayed(0, 3000);
break;
default:
break;
}
return true;
}
}
/**
* ViewPager数据适配器
*
* @author Kevin
*
*/
class GuideAdapter extends PagerAdapter {
@Override
public int getCount() {
return IMAGES.length;
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// ImageView imageView = new ImageView(Activity_Other.this);
// imageView.setScaleType(ScaleType.FIT_XY);
// loader.displayImage(IMAGES[position], imageView, options);
// container.addView(imageView);
// imageView.setOnTouchListener(new NewTouchListener());
// return imageView;
View imageLayout = View.inflate(Activity_Other.this,
R.layout.item_pager_image, null);
ImageView imageView = (ImageView) imageLayout
.findViewById(R.id.image);
imageView.setScaleType(ScaleType.FIT_XY);
ProgressBar spinBar = (ProgressBar) imageLayout
.findViewById(R.id.loading);
loader.displayImage(IMAGES[position], imageView, options,
new MySimpleLoading(spinBar));
container.addView(imageLayout);
imageView.setOnTouchListener(new NewTouchListener());
return imageLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
class MySimpleLoading extends SimpleImageLoadingListener {
ProgressBar spinBar;
public MySimpleLoading(ProgressBar spinBar) {
// TODO Auto-generated constructor stub
this.spinBar = spinBar;
}
//开始加载
@Override
public void onLoadingStarted(String imageUri, View view) {
// TODO Auto-generated method stub
spinBar.setVisibility(View.VISIBLE);
}
//加载失败
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
// TODO Auto-generated meth |