Android EditText Vertical Scrolling Problem

后端 未结 5 1707
猫巷女王i
猫巷女王i 2020-12-06 03:20

I\'m using an EditText of some predefined size, however when a user enters more text then fits in the text box, they aren\'t able to scroll the text with touch. Scrolling do

相关标签:
5条回答
  • 2020-12-06 03:32

    make the changes like the following to get scroller in your EditText

    questionEntry.setScroller(new Scroller(myContext)); 
    questionEntry.setMaxLines(1); 
    questionEntry.setVerticalScrollBarEnabled(true); 
    questionEntry.setMovementMethod(new ScrollingMovementMethod()); 
    

    How to make edittext in Android scrollable?

    Donot forget to vote if you feel my response is helpful for you

    Thanks Deepak

    0 讨论(0)
  • 2020-12-06 03:34

    If you would like the text to scroll horizontally, define in your EditText XML tag:

    android:scrollHorizontally="true"
    

    If you would like a vertical scroll, define in your EditText XML tag:

    android:scrollbars = "vertical"
    

    Hope this helped.

    0 讨论(0)
  • 2020-12-06 03:38

    @Sunil Kumar Sahoo answer worked for me but I had to remove the line

    questionEntry.setMaxLines(1); 
    
    0 讨论(0)
  • 2020-12-06 03:48

    A simple way to do scroll-able text in edittext if parent is NestedScrollView or ScrollView

    XML code

    android:gravity="top"
    android:inputType="text|textMultiLine"
    android:lines="5"
    

    Use below code for Kotlin

        editText.setOnTouchListener { v, event ->
            if (v.id == R.id.editText) {
                v.parent.requestDisallowInterceptTouchEvent(true)
                when (event.action and MotionEvent.ACTION_MASK) {
                    MotionEvent.ACTION_UP -> v.parent.requestDisallowInterceptTouchEvent(false)
                }
            }
            false
        }
    
    0 讨论(0)
  • 2020-12-06 03:54

    In java

     EditText dwEdit = (EditText) findViewById(R.id.DwEdit);       
     dwEdit.setOnTouchListener(new OnTouchListener() {
           public boolean onTouch(View view, MotionEvent event) {
                // TODO Auto-generated method stub
                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;
            }
        });
    

    In xml

    <EditText
    android:id="@+id/DwEdit"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minLines="10"
    android:scrollbarStyle="insideInset"
    android:scrollbars="vertical" 
    android:overScrollMode="always"
    android:inputType="textCapSentences">
    </EditText> 
    
    0 讨论(0)
提交回复
热议问题