ScrollView中EditText导致自动滚动
最近在做项目中,当有EditText嵌套在ScrollView中,点击ScrollView中的子控件时,EditText自动抢占焦点出现在最上面的位置,这样的体验极为不好。
这个是EditText获取焦点导致的,只要在父容器中加入
android:focusable="true" android:focusableInTouchMode="true"
ps:
这样只解决了一部分情况,还有一个方法可以彻底解决这个问题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; } });