Scrollable vertically and horizontally EditText that doesn't automatically break text to the next line

前端 未结 2 797
暖寄归人
暖寄归人 2020-12-22 06:26

I need an activity that look like a simple text editor:
full-screen EditText with submit button below it.

Important:
1. EditText has to scroll both verti

相关标签:
2条回答
  • 2020-12-22 07:00

    EditText actually has scrolling already built in, so you don't have to use a ScrollView. The only thing is that it doesn't support flings.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <EditText
            android:id="@+id/some_edittext"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="top|left"
            />
    
        <Button
            android:id="@+id/submit_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Submit"/>
    
    </LinearLayout>
    

    To stop the automatic wrapping, you can activate horizontal scrolling:

    EditText editText = (EditText) findViewById(R.id.some_edittext);
    editText.setHorizontallyScrolling(true);
    editText.setMovementMethod(new ScrollingMovementMethod());
    
    0 讨论(0)
  • 2020-12-22 07:25

    I think you could set your EditText attribute android:maxLines="1" initially.

    And when "new line" button is clicked, you can increase that value programmatically using setMaxLines(int) method.

    EditText.setMaxLines(int) 
    

    here's the doc -> link

    Hope this helped.

    0 讨论(0)
提交回复
热议问题