可垂直和水平滚动的EditText不会自动将文本中断到下一行 [英] Scrollable vertically and horizontally EditText that doesn't automatically break text to the next line
问题描述
我需要一个看起来像一个简单的文本编辑器的活动:
全屏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屋!