设为首页 加入收藏

TOP

ViewPager+handler实现轮播(三)
2017-10-12 11:29:09 】 浏览:4451
Tags:ViewPager handler 实现
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
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇圆形ImageView(可设置边缘厚度和.. 下一篇仿微信底部TAG完美渐变

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目