How to scroll the edittext inside the scrollview

64,122

Solution 1

Try this..

Add below lines into your EditText

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

Example

   <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="15dp"
        android:background="#eeeeee"
        android:inputType="textMultiLine"
        android:singleLine="false"
        android:overScrollMode="always"
        android:scrollbarStyle="insideInset"
        android:scrollbars="vertical"
        android:text="Android applications normally run entirely on a single thread by              default the “UI thread” or the “main thread”.
        android:textAppearance="?android:attr/textAppearanceMedium" >
    </EditText>

EDIT

Programmatically

youredittext.setOnTouchListener(new OnTouchListener() {

      public boolean onTouch(View v, MotionEvent event) {
            if (youredittext.hasFocus()) {
               v.getParent().requestDisallowInterceptTouchEvent(true);
               switch (event.getAction() & MotionEvent.ACTION_MASK){
               case MotionEvent.ACTION_SCROLL:
                      v.getParent().requestDisallowInterceptTouchEvent(false);
                      return true;
                }
             }
             return false;
       }
});

Solution 2

First add this at XML

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

Then add the same above "OnTouch" but make it return "false" not "true"

public boolean onTouch(View view, MotionEvent event) {

                    if (view.getId() == R.id.DwEdit) {
                        view.getParent().requestDisallowInterceptTouchEvent(true);
                        switch (event.getAction()&MotionEvent.ACTION_MASK){
                        case MotionEvent.ACTION_UP:
                            view.getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                        }
                    }
                    return false;
}

Solution 3

Kotlin version

Add the following lines to the EditText in your xml:

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

Add this to the Activity/Fragment:

myEditText.setOnTouchListener { view, event ->
   view.parent.requestDisallowInterceptTouchEvent(true)
   if ((event.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
       view.parent.requestDisallowInterceptTouchEvent(false)
   }
   return@setOnTouchListener false
}

Solution 4

you should use NestedScrollView class. This class support child scrolling inside parent scrolling. This class can be a child or a parent.

<android.support.v4.widget.NestedScrollView         
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#d6d8d9">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="512"
                android:text=" your content"/>
        <android.support.v4.widget.NestedScrollView
            android:layout_below="@id/ll_button"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="#d6d8d9">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:text="your content"
                android:maxLines="512"/>    
        </android.support.v4.widget.NestedScrollView>       
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>           

Solution 5

Use this code it's working

In XML

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

In programming

edittext.setOnTouchListener(new View.OnTouchListener() {

    public boolean onTouch(View view, MotionEvent event) {

        if (view.getId() == R.id.edittext) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_UP:
                view.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
        }
        return false;
    }
});
Share:
64,122
Maveňツ
Author by

Maveňツ

Hi all, I'm currently working as Android developer ,interested in a wide-range of technology topics, including programming languages, opensource and any other cool technology that catches my eye. I love developing apps for Android(native), designing and coding.Learning Cordova just for improving skills. . Got Assist Person badge from HappyMan and naruto. Got good badge from TheLittleNaruto man kami farsi baladam FreeTime work. :D هنگامی که من در پایان زندگیام در مقابل خدا میایستم، من امیدوارم حتی یک بیت از استعدادم را باقی نگذاشته باشم و بتوانم بگویم، من هر چیزی را که تو به من عطا کردی، مورد استفاده قرار دادم... Loving more than 3 years to inVINSIBLE 'ANDROID' &lt;3 Loving them too: Java Android Swings Html5 CSS3 Jquery C++ JSF XML ASP.NET दखल ना दो जिंदगी में उनकी,अगर समझते होंगे कुछ तुम्हे तो खुद चले आयेंगे। Interest: List item New Technologies New Android Libraries 9gag stuffs especially the NSFW Mobile &amp; Computer Games Boobies number of Android apps in the market: 1170543 &amp; total downloads 50 billion and Percentage of low quality apps: 21% till 18 jan 2014

Updated on January 12, 2021

Comments

  • Maveňツ
    Maveňツ over 3 years

    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.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:background="@android:color/holo_blue_light"
            android:gravity="center" >
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="View Complaint"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:padding="20dp" >
                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:text="Order Number 0100C1"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="Name of ClientClient 1"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="Subject : Measurement Issues"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="25dp"
                    android:text="Description"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:text="Lorem ipsum dolor sit amet, sapien etiam, nunc amet dolor ac odio mauris justo. Luctus arcu, urna praesent at id quisque ac. Arcu massa vestibulum malesuada, integer vivamus el/ eu "
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >
                    <TextView
                        android:id="@+id/textView7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="2dp"
                        android:text="Assign to"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                    <Spinner
                        android:id="@+id/spinner1"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:entries="@array/array_name" />
                </LinearLayout>
                <EditText
                    android:id="@+id/editText1"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_marginTop="15dp"
                    android:background="#eeeeee"
                    android:inputType="textMultiLine"
                    android:singleLine="false"
                    android:text="Android applications normally run entirely on a single thread by              default the “UI thread” or the “main thread”.
            
                android:textAppearance="?android:attr/textAppearanceMedium" ></EditText>
                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Comment History"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="fill_parent"
                    android:layout_height="147dp"
                    android:src="@drawable/adddd" />
                <CheckBox
                    android:id="@+id/checkBox1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Close Complaints"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
                <Button
                    android:id="@+id/login"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:layout_below="@+id/ll"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="15dp"
                    android:background="@drawable/login_btn"
                    android:text="Submit"
                    android:textColor="@android:color/holo_blue_dark"
                    android:textSize="25dp"
                    android:textStyle="bold" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
    

    enter image description here

    Can you guys help me in that . I think editText is getting the focus when cursor is inside it.

    Thanks..!!!!!

  • Maveňツ
    Maveňツ almost 10 years
    by xml way when i touch inside the edittext then softkeyboard opens but after implementing the programtically keyboard also refuses to come. In both the cases there is no scroll inside the editText.
  • Kishan Vaghela
    Kishan Vaghela over 8 years
    when press enter from keyboard while typing It is scrolling parent scrollview
  • Patel vaishu
    Patel vaishu over 7 years
    It's Correct , it 's helpful for me
  • Kannan_SJD
    Kannan_SJD over 7 years
    @KishanVaghela I have the same issue.. How did you resolve it?
  • Adam
    Adam almost 7 years
    My answer above is dated. @HungNM2 has the more modern and correct answer.
  • Eduardo Reis
    Eduardo Reis over 6 years
    I have a ScrollView which contains several view, and just one of them is a EditText. Does this solution only assumes one EditText inside the ScrollView? Or adding an extra ScrollView just to wrap the EditText?
  • Huy Tower
    Huy Tower over 6 years
    Great answer.Thanks.
  • thevoiceless
    thevoiceless over 5 years
    The XML method never worked for me, and a previous version of the programmatic method worked but also prevented the soft keyboard from showing. The programmatic method was updated on August 11 and it now works flawlessly for me.
  • MNKY
    MNKY about 5 years
    𝑨𝑾𝑬𝑺𝑶𝑴𝑬, 𝑻𝑯𝑨𝑵𝑲𝑺 𝑰'𝑽𝑬 𝑩𝑬𝑬𝑵 𝑳𝑶𝑶𝑲𝑰𝑵𝑮 𝑭𝑶𝑹 𝑻𝑯𝑬 𝑺𝑶𝑳𝑼𝑻𝑰𝑶𝑵 𝑭𝑶𝑹 𝑫𝑨𝒀𝑺!!
  • Siddharth Thakkar
    Siddharth Thakkar almost 5 years
    Use both, in xml as well as programmatically, it works
  • Pratik Butani
    Pratik Butani over 4 years
    Write full onTouch as it above answer is removed, no one will understood how to set onTouch
  • Nice umang
    Nice umang over 4 years
    THANKS it is working but one issue occurred it makes my text font too small.have you any solution for it ?
  • Asadullah Mumtaz
    Asadullah Mumtaz almost 4 years
    Thanks, man this works perfectly when I add these properties in XML but my case is that I am creating edit text dynamically, now the issue is that the scroll bar is not showing just even I have changed the color of the scrollbar but no luck.
  • CoolMind
    CoolMind over 3 years
    Thanks! Programmatic solution works. See Kotlin solutions below. Also performClick() or @SuppressLint("ClickableViewAccessibility") can be added.
  • ONE
    ONE over 3 years
    The XML doesn't work for me BUT the programmatic method worked perfectly for me. +1 -- Cheers!
  • Divy Soni
    Divy Soni over 3 years
    onTouch method worked for me, without adding properties in layout.