6

I have created a scroll view with a EditText in the middle that is multiLine (Scrollable). When that view is edited and lines are added beyond the allowed height it scrolls as expected. However, the parent scroll view for the whole container also scrolls as if it is following the text.

    <ScrollView
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:background="#F7F3DE"
    p1:id="@+id/scrollview">
    <RelativeLayout
        p1:layout_width="match_parent"
        p1:layout_height="match_parent"
        p1:clickable="true"
        p1:focusableInTouchMode="true"
        p1:id="@+id/realtiveLayout">
        <EditText
                p1:id="@+id/editText"
                p1:focusableInTouchMode="true"
                p1:layout_width="match_parent"
                p1:layout_height="150dp"
                p1:hint="Comments"
                p1:background="#00000000"
                p1:textSize="16sp"
                p1:textColor="#555555"
                p1:gravity="top"
                p1:minLines="5"
                p1:maxLines="5"
                p1:inputType="textCapSentences|textMultiLine"
                p1:scrollHorizontally="false"
                p1:layout_marginTop="5dp"
                p1:textColorHint="#A9A9A9" />
        </RelativeLayout>
    </ScrollView>

Has anyone seen or know of a resolution for this issue?

(Note: This is not a question of how to scroll one instead of the other by touch as that I already understand. It is a question of the main scrollview moving while typing inside the EditText even though the text is not going lower but scrolling instead.

Zach S.
  • 130
  • 1
  • 9
  • Can you take a short video/gif of your issue on an emulator? This would help visualize the problem I think. My initial guess is that you might lock the outer scrollview when the `EditText` is `Focused` on? This link might be of help: http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically – Timothy Frisch Jun 04 '15 at 20:16

1 Answers1

1

There is an answer here: https://stackoverflow.com/a/28180281/3956566

Using this Managing Touch Events in a ViewGroup

Each child touch needs to provide an intercept that returns the parents touch event as false. To disable the parents touch event whilst the child element is being used. You can do this by creating an onInterceptTouchEvent(MotionEvent ev) in your java.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onTouchEvent will be called and we do the actual
     * scrolling there.
     */
    //  ...
    // In general, we don't want to intercept touch events. They should be 
    // handled by the child view.
    return false;
}

EDIT This answer provided by

https://stackoverflow.com/users/498468/carl-odonnell

should help:

https://stackoverflow.com/a/5090420/3956566 Where the scrollview is disabled when the text field is touched.

// Get the ScrollView
final ScrollView myScroll = (ScrollView) findViewById(R.id.display_scrollview);


// Disable Scrolling by setting up an OnTouchListener to do nothing
myScroll.setOnTouchListener( new OnTouchListener(){ 
@Override
public boolean onTouch(View v, MotionEvent event) {
    return true; 
    }
});

// Enable Scrolling by removing the OnTouchListner
tvDisplayScroll.setOnTouchListener(null);   
Community
  • 1
  • 1
  • This is useful, and I have applied this in my code already. However, this only addresses touch events and is not what I am discussing. The issue I am talking about does not involve anything touching the screen but scrolling based on multi line text input. i.e. pressing return more times then there are lines, it starts scrolling, the scrolling happens both within the edit text and within the scrollview. – Zach S. Jun 04 '15 at 20:31
  • I may upload a gif/video later, but it is not a touch affecting the scroll I am discussing. It is merely returning lines that exceed the length of the edittext, which causes it to scroll, but also scrolls the scrollview. It is in no way associated with a touch and no touch event is called when it happens. – Zach S. Jun 04 '15 at 20:36
  • I have already implemented this in my solution in a way that did what I wanted to happen in that aspect. However, even with this, the scrollview will still scroll when typing in the edit text as it word wraps and will continue to scroll with every new line until the scrollview hits the bottom of the screen even if the edit text is completely now not visible above the top of the screen. – Zach S. Jun 04 '15 at 20:44