设为首页 加入收藏

TOP

viewPager+Fragment实现左右划屏(二)
2015-07-24 05:35:50 来源: 作者: 【 】 浏览:13
Tags:viewPager Fragment 实现 左右
); int screenW = dm.widthPixels;// 获取分辨率宽度 offset = (screenW / 3 - bmpW) / 2;// 计算偏移量 Matrix matrix = new Matrix(); matrix.postTranslate(offset, 0); imageView.setImageMatrix(matrix);// 设置动画初始位置 } /** * * 头标点击监听 3 */ private class MyOnClickListener implements OnClickListener { private int index = 0; public MyOnClickListener(int i) { index = i; } public void onClick(View v) { viewPager.setCurrentItem(index); } } public class MyOnPageChangeListener implements OnPageChangeListener { int one = offset * 2 + bmpW;// 页卡1 -> 页卡2 偏移量 int two = one * 2;// 页卡1 -> 页卡3 偏移量 public void onPageScrollStateChanged(int arg0) { } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageSelected(int arg0) { Animation animation = new TranslateAnimation(one * currIndex, one * arg0, 0, 0);// 显然这个比较简洁,只有一行代码。 currIndex = arg0; animation.setFillAfter(true);// True:图片停在动画结束位置 animation.setDuration(300); imageView.startAnimation(animation); } } }

注:要利用这种方式的话,自动滑动的ImageView需要自己找一张图片,如果你想要只要标题汉字滑动,下面的线不滑动的话,可以直接用ViewPager自己的属性。


  

        
   
    
  



首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇vector shrink_to_fit 下一篇HDU 3415 Max Sum of Max-K-sub-s..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: