android 滑动控件 ViewFlipper

<ViewFlipper
    android:id="@+id/vf"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:autoStart="true"
    android:flipInterval="3000"
    android:inAnimation="@anim/text_in"
    android:outAnimation="@anim/text_out"
    android:paddingTop="2dp"
    android:paddingBottom="2dp"
    ></ViewFlipper>
vf.addview(view);

第一个坑:切换页面时会产生重影问题,这个比较好解决

直接在activity中添加 

vf.stopFlipping();
 vf.startFlipping(); 

控制一下就行了。

第二个坑,在手机锁屏解锁之后,ViewFlipper会停止滚动,并且startFlipping失效。

看了源码发现有个值在锁屏之后没有设置为true

mUserPresent 

百度了一下说没有打开锁屏功能。

还有就是反射修改值暂时可以正常使用

try{
Class c=vf.getClass();
Field z=c.getDeclaredField("mUserPresent");
    z.setAccessible(true);
    z.set(vf, true);
    vf.setDisplayedChild(0);
    vf.startFlipping();
}catch (IllegalAccessException e){
    e.printStackTrace();
}catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();}






猜你喜欢

转载自blog.csdn.net/zuola8579/article/details/80182480