最近使用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();
}
}