ScrollView nested EditText sliding problem

Keywords: Android

ScrollView nested single Edittext problem

In today's project, the requirement is to write a very simple edittext input box, but when the number of input words is too long, it needs to slide up and down to view all the words, because there is a "OK" button at the bottom of the page, but at the beginning, the problem in the input box can't slide. I thought of this problem at the beginning, but I tried many methods, but they can't, Finally, it's a trial solution, not to mention, paste the code:

     <ScrollView
        android:id="@+id/sc_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:minHeight="360dp"
        android:scrollbars="none">
        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="15dp"
            android:layout_marginTop="10dp"
            android:background="@null"
            android:gravity="top|start"
            android:hint="@string/FeedBackViewController_Placeholder"
            android:lineSpacingMultiplier="1.0"
            android:paddingEnd="10dp"
            android:paddingStart="10dp"
            android:maxHeight="450dp"  //At the beginning, this one didn't add, but it couldn't slide
            android:textSize="@dimen/font_size16"/>
    </ScrollView>

The code needs to:

           editText.setOnTouchListener(new View.OnTouchListener() {
                @Override
                    public boolean onTouch(View v, MotionEvent event) {
                      // Solve the problem that EditText nested in scrollView cannot slide up and down
                         v.getParent().requestDisallowInterceptTouchEvent(true);
                        switch (event.getAction() & MotionEvent.ACTION_MASK) {
                           case MotionEvent.ACTION_UP:
                       v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                     }
                     return false;
                   }
            });

Posted by eoghain on Sun, 03 May 2020 14:46:56 -0700