ScrollView中EditText导致自动滚动问题

Mar 24 2015

这个是EditText获取焦点导致的,只要在父容器中加入

1
2
android:focusable="true"  
android:focusableInTouchMode="true"

这样只解决了一部分情况,还有一个方法可以彻底解决这个问题:

1
2
3
4
5
6
7
8
9
10
11
ScrollView view = (ScrollView)findViewById(R.id.scrollView);
view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
return false;
}
});

就能够轻松解决了: )


Kommentare: