How to make edittext in Android scrollable?

2019-01-14 21:07发布

I am creating a dynamic layout that contains an edit text. I want to make this edit text scrollable.

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

Using this code I made my edit text scrollable. But the problem is when I am typing something. If it reaches the end of the edit text, it will stop typing my text and not automatically jump to the next line. If I press the enter key, it will jump. I want to make it automatic.

3条回答
贪生不怕死
2楼-- · 2019-01-14 21:27
questionEntry.setScroller(new Scroller(myContext)); 
questionEntry.setMaxLines(1); 
questionEntry.setVerticalScrollBarEnabled(true); 
questionEntry.setMovementMethod(new ScrollingMovementMethod()); 

i made some changes in my previous code.
above posted is my new code.

it s working...thanks for all

查看更多
太酷不给撩
3楼-- · 2019-01-14 21:35

I know this question has already got an answer, but if you wish to get the same result via XML, change

android:inputType="text"

to

android:inputType="textMultiLine"

for a vertically scrollable EditText.

查看更多
萌系小妹纸
4楼-- · 2019-01-14 21:36

Try this, Hope it Helps

questionEntry.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == R.id.inputFormComments) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_UP:
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
            }
        }
        return false;
    }
});
查看更多
登录 后发表回答