How to scroll the edittext inside the scrollview

前端 未结 12 1957
南笙
南笙 2020-12-02 10:27

I have a scrollview inside which there is a editext which is multiline. I want to scroll the edittext to see the lower content but it can\'t be done.

12条回答
  •  自闭症患者
    2020-12-02 11:16

    This will scroll the EditText and make it editable:

    First in the XML file, add this:

    android:overScrollMode="always"
    android:scrollbarStyle="insideInset"
    android:scrollbars="vertical"
    

    Then in the Java file, add this:

    EditText.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View view, MotionEvent motionEvent) {
               view.getParent().requestDisallowInterceptTouchEvent(true);
               switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
                   case MotionEvent.ACTION_SCROLL:
                      view.getParent().requestDisallowInterceptTouchEvent(false);
                       return true;
                   case MotionEvent.ACTION_BUTTON_PRESS:
                       InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                       imm.showSoftInput(EditText, InputMethodManager.SHOW_IMPLICIT);
               }
               return false;
           }
    });
    

提交回复
热议问题