不能水平和垂直滚动的EditText不会自动将文本中断到下一行 [英] Scrollable vertically and horizontally EditText that doesn't automatically break text to the next line

查看:56
本文介绍了不能水平和垂直滚动的EditText不会自动将文本中断到下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个类似于简单文本编辑器的活动:
全屏EditText,并在其下方带有提交"按钮.

重要事项:
1. EditText必须垂直和水平滚动
2.仅当用户单击下一行按钮时,输入文本才转到下一行
3. EditText填充屏幕顶部和按钮之间的整个空间

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 vertically and horizontally
2. Input text goes to the next line ONLY when the user clicks nextline button
3. EditText fills the whole space between the top of the screen and the button

我的代码:

<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">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true">

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">

                    <EditText
                        android:id="@+id/some_edittext"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="top|left"
                        />

            </HorizontalScrollView>

    </ScrollView>

    <Button
        android:id="@+id/submit_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Submit"/>

</LinearLayout>

为什么不好:
EditText在到达行尾时自动将文本中断到下一行

Why bad:
EditText AUTOMATICALLY breaks text to the next line as it reaches the end of the row

在我将fillViewport设置为true之前,它工作正常.但是否则EditText不会填满整个屏幕

It worked fine before I set fillViewport to true. But otherwise EditText doesn't fill entire screen

预先感谢

推荐答案

EditText 实际上已经内置了滚动功能,因此您不必使用 ScrollView .唯一的事情是它不支持猛击.

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());

这篇关于不能水平和垂直滚动的EditText不会自动将文本中断到下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆