处理小图标位子

/** 
    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);           	
		}
	}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值