如何在android中滚动显示多行文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10138663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display multiple lines of text with scrolling in android?
提问by Sanchit Paurush
I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText
, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView
, it also does not scroll the text properly as I wanted.
我想在我的应用程序中在特定范围内显示多行文本,以便用户可以滚动查看其他行。我试过EditText
,但它会在它上面生成键盘并且不能正确滚动。然后我尝试了TextView
,它也没有像我想要的那样正确滚动文本。
Is there any other option available? If No, then how to scroll the text vertically in TextView
or EditText
? I want to scroll the text on drag as in WebView
. NOT auto scroll.
还有其他选择吗?如果否,那么如何在TextView
或 中垂直滚动文本EditText
?我想在拖动时滚动文本WebView
。不是自动滚动。
回答by Arif Nadeem
You can limit the Height of TextView
to match the number of lines you user wants to see, then simply put your TextView
in a ScrollView
您可以限制高度TextView
以匹配您用户想要看到的行数,然后只需将您TextView
的ScrollView
I had done a simple example to demonstrate this...
我做了一个简单的例子来证明这一点......
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="@+id/tv1"
/>
</ScrollView>
回答by Akash Singh
It is possible to create multiline text view with scroll view. I used the following code in your application:
可以使用滚动视图创建多行文本视图。我在您的应用程序中使用了以下代码:
Txt_VistaRecetasola = (TextView) findViewById(R.id.txt_vistarectsola);
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);
回答by Sandip Jadhav
Check below code
检查下面的代码
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="17dip"
android:inputType="textMultiLine"
android:scrollbars="vertical"
/>
回答by AAnkit
Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.
尝试使用 Edittext 使其不可编辑,因此在这种情况下它不会允许键盘弹出。
回答by Pallavi
android:windowSoftInputMode="stateAlwaysHidden"
in your Manifest file in the activity where you have your EditText.
android:windowSoftInputMode="stateAlwaysHidden"
在您拥有 EditText 的活动中的清单文件中。