修改ViewPager调用setCurrentItem时,滑屏的速度 ,解决滑动之间切换动画难看
在使用ViewPager的过程中,有需要直接跳转到某一个页面的情况,这个时候就需要用到ViewPager的setCurrentItem方法了,它的意思是跳转到ViewPager的指定页面,但在使用这个方法的时候有个问题,跳转的时候有滑动效果,当需要从当前页面跳转到其它页面时,跳转页面跨度过大、或者ViewPager每个页面的视觉效果相差较大时,通过这种方式实现ViewPager跳转显得很不美观,怎么办呢,我们可以去掉在使用ViewPager的setCurrentItem方法时的滑屏速度,具体实现如下:
一、自定义一个Scroll类,用于控制ViewPager滑动速度:
import Android.view.animation.Interpolator;
import android.widget.Scroller;
public class FixedSpeedScroller extends Scroller {
private int mDuration = 0;
public FixedSpeedScroller(Context context) {
super(context);
}
public FixedSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
public FixedSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) {
super(context, interpolator, flywheel);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, mDuration);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy) {
super.startScroll(startX, startY, dx, dy, mDuration);
}
}
二、在初始化ViewPager时,对ViewPager作如下设置:
* 设置ViewPager的滑动速度
*
* */
private void setViewPagerScrollSpeed( ){
try {
Field mScroller = null;
mScroller = ViewPager.class.getDeclaredField("mScroller");
mScroller.setAccessible(true);
FixedSpeedScroller scroller = new FixedSpeedScroller( mViewPager.getContext( ) );
mScroller.set( mViewPager, scroller);
}catch(NoSuchFieldException e){
}catch (IllegalArgumentException e){
}catch (IllegalAccessException e){
}
}
修改ViewPager调用setCurrentItem时,滑屏的速度 ,解决滑动之间切换动画难看的更多相关文章
- 修改ViewPager调用setCurrentItem时,滑屏的速度
原文摘自: 修改ViewPager调用setCurrentItem时,滑屏的速度 在使用ViewPager的过程中,有需要直接跳转到某一个页面的情况,这个时候就需要用到ViewPager的setCur ...
- ##解决 ViewPager 调用 notifyDataSetChanged()无刷新:原理、解决办法##
一.原理 转自:http://www.cnblogs.com/maoyu417/p/3740209.html 转载 http://www.67tgb.com/?p=624 最近项目结束,搞了一次代码分 ...
- 关于使用CodeFirst,修改类或上下文时操作数据库报错解决方法
在操作已经创建好的数据库时,若是添加新的实体类或者修改原有数据库上下文,会报如下错误: The model backing the 'StudentDbContext' context has cha ...
- Activity设置切换动画时黑屏问题的解决
//当这么设置的时候.打开Acticity的时候会黑屏一下 overridePendingTransition(R.anim.activity_open,0); //改成例如以下代码 完美解决这个问题 ...
- SpringBoot高版本修改为低版本时测试类报错解决
有时在使用idea通过Spring Initailizr创建项目时,默认只能创建最近的版本的SpringBoot项目. 这是如果想要换成版本,就可以在项目创建好了之后,在pom文件中直接将版本修改过来 ...
- localforage调用setItem时出现DOMException错误的解决方法
今天使用localforage时出现下面的错误: Uncaught (in promise) DOMException transaction.onabort.transaction.onerror ...
- 在Mac上用bootcamp安装windows,使用Android studio启动模拟器时蓝屏问题的解决方法
原链接 https://medium.com/@andrea.bresolin/windows-10-on-mac-with-boot-camp-making-intel-haxm-work-with ...
- 利用轮播原理结合hammer.js实现简洁的滑屏功能
最近有个任务,做一个非常小的h5的应用,只有2屏,需要做横向的全屏滑动切换和一些简单的动画效果,之前做这种东西用的是fullpage.js和jquery,性能不是很好,于是就想自己动手弄一个简单的东西 ...
- (转)【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)
转自: http://smallwoniu.blog.51cto.com/3911954/1308959 现如今主流的Android应用中,都少不了左右滑动滚屏这项功能,(貌似现在好多人使用智能机都习 ...
随机推荐
- luogu1501 [国家集训队]Tree II
lct裸题 #include <iostream> #include <cstdio> using namespace std; typedef long long ll; i ...
- xcode8.1 autolayout 找不到 Update Frames 按钮
- python - work - 2
#-*- coding:utf-8 -*-# author:jiaxy# datetime:2018/11/3 11:48# software: PyCharm Community Edition d ...
- Flask_配置文件
flask中的配置文件是一个flask.config.Config对象(继承字典),默认配置为: default_config = ImmutableDict({ 'DEBUG': get_debug ...
- match_parent, wrap_content, 和 fill_parent 区别联系
fill_parent -1 The view should be as big as its parent (minus padding). This constant is deprecat ...
- C语言知识点(4)
一.while. dowhile. 1.while while (表达式) { 语句: … 语句: } 2.while do { printf(“%d/n,I);…}while (i<=1 ...
- PHP_命名空间
namespace NS; define(__NAMESPACE__ .'\foo','111'); define('foo','222'); echo foo; // 111. echo \foo; ...
- getBoundingClientRect说明
getBoundingClientRect用于获取某个元素相对于视窗的位置集合. 1.语法:这个方法没有参数. rectObject = object.getBoundingClientRect() ...
- 算法复习——数位dp
开头由于不知道讲啥依然搬讲义 对于引入的这个问题,讲义里已经很清楚了,我更喜欢用那个建树的理解···· 相当于先预处理f,然后从起点开始在树上走··记录目前已经找到了多少个满足题意的数k,如果枚举到第 ...
- tomcat Enabling JMX Remote
wiki 利用JMX做存活监控 cat /opt/wiki/work/bin/setenv.sh | grep jmxremoteCATALINA_OPTS="-Dcom.sun.manag ...