看到很多博客说在ScrollView的子布局里加入
android:focusable="true"
android:focusableInTouchMode="true"
本人是一个Activity四个fragment,作为页卡切换。
在每个fragment的ScrollView下同上述代码写入,发现只有第一个fragment的ScrollView没有自动滚动,
第二个依然滚动,再次百度了下,找到了解决方法。PS:博客地址我忘了。。。后来尝试再找,然而没找到。
解决方法:重写ScrollView,在其内重写如下方法
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ScrollView;
/**
* Created by lee on 16-8-5.
*/
public class NoAutoSlideScrollView extends ScrollView {
public NoAutoSlideScrollView(Context context) {
super(context);
}
public NoAutoSlideScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NoAutoSlideScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
return 0;
}
}
复写computeScrollDeltaToGetChildRectOnScreen,导入Rect类即可,之后xml里引用下