HorizontalScrollView 初始化第一次时使用smoothScrollTo无效的解决办法

来源:互联网 发布:淘宝小样四大靠谱店 编辑:程序博客网 时间:2024/06/07 01:20

最近使用HorizontalScrollView 来封装水平滚动布局时 在初始化后第一次调用smoothScrollTo时 没有发生滚动
通过post时发现可行 在此做为笔记

post(new Runnable() {      @Override      public void run() {            smoothScrollTo(f, 0);      }  });  

假如当HorizontalScrollView发生滚动时也将无效 要调用之前需停止滚动

public void abortAnimation() {        Class superView = this.getClass().getSuperclass();        try {            Field field = superView.getDeclaredField("mScroller");            field.setAccessible(true);            Class OverScroller = Class.forName(field.getClass().getName());            Method abortAnimation = OverScroller.getDeclaredMethod("abortAnimation");            abortAnimation.invoke(OverScroller);        } catch (SecurityException e) {            e.printStackTrace();        } catch (NoSuchFieldException e) {            e.printStackTrace();        } catch (IllegalArgumentException e) {            e.printStackTrace();        } catch (ClassNotFoundException e) {            e.printStackTrace();        } catch (InvocationTargetException e) {            e.printStackTrace();        } catch (NoSuchMethodException e) {            e.printStackTrace();        } catch (IllegalAccessException e) {            e.printStackTrace();        }    }