首页 > 其他 > 详细

处理小图标位子

时间:2014-12-12 19:16:15      阅读:297      评论:0      收藏:0      [点我收藏+]
/** 
    2      * 初始化动画,这个就是页卡滑动时,下面的横线也滑动的效果,在这里需要计算一些数据 
    3 */  
	private int offset = 0;// 动画图片偏移量 
	private int bmpW;// 动画图片宽度 
	private ImageView imageView;
	private int currIndex = 0;// 当前页卡编号 
 
   private void InitImageView() {  
       imageView= (ImageView)findViewById(R.id.main_cursor);  
      
       bmpW = BitmapFactory.decodeResource(getResources(), android.R.drawable.button_onoff_indicator_on).getWidth();// 获取图片宽度         
       DisplayMetrics dm = new DisplayMetrics();  
       getWindowManager().getDefaultDisplay().getMetrics(dm);  
       int screenW = dm.widthPixels;// 获取分辨率宽度  
       offset = (screenW / 3 - bmpW) / 2;// 计算偏移量  
       Matrix matrix = new Matrix();  
       matrix.postTranslate(offset, 0);  
       imageView.setImageMatrix(matrix);// 设置动画初始位置  
   }  
	class ViewPagerListener implements OnPageChangeListener{
		int one = offset * 2 + bmpW;// 页卡1 -> 页卡2 偏移量  
        int two = one * 2;// 页卡1 -> 页卡3 偏移量  
		@Override
		public void onPageScrollStateChanged(int arg0) {
			
		}
		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			
		}
		@Override
		public void onPageSelected(int position) {
			//actionBar.setSelectedNavigationItem(position);
			Animation animation = new TranslateAnimation(one*currIndex, one*position, 0, 0);//显然这个比较简洁,只有一行代码。  
            currIndex = position;  
            animation.setFillAfter(true);// True:图片停在动画结束位置  
            animation.setDuration(300);  
            imageView.startAnimation(animation);           	
		}
	}

处理小图标位子

原文:http://blog.csdn.net/f5647/article/details/41896245

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!