TextView取消自动换行并设置水平滚动
2015-04-06 02:12
447 查看
原博客地址:http://blog.csdn.net/u012964281/article/details/44885697
假如需要显示一段代码,通常代码一行的长度超出了手机屏幕的宽度,这时候TextView默认会选择自动换行,代码由一行变成了两行,很不美观。
所以,这篇文章记录如何取消自动换行并且设置TextView为水平滚动。
布局代码:
[html] view
plaincopy
<TextView
android:id="@+id/article_content_code_TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#abcabc" />
java代码:
[java] view
plaincopy
textView = (TextView) convertView
.findViewById(R.id.article_content_code_TextView);
textView.setText(element.getCode());
textView.setMovementMethod(ScrollingMovementMethod
.getInstance());
textView.setHorizontallyScrolling(true); // 不让超出屏幕的文本自动换行,使用滚动条
textView.setFocusable(true);
这样就OK了。
假如需要显示一段代码,通常代码一行的长度超出了手机屏幕的宽度,这时候TextView默认会选择自动换行,代码由一行变成了两行,很不美观。
所以,这篇文章记录如何取消自动换行并且设置TextView为水平滚动。
布局代码:
[html] view
plaincopy
<TextView
android:id="@+id/article_content_code_TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#abcabc" />
java代码:
[java] view
plaincopy
textView = (TextView) convertView
.findViewById(R.id.article_content_code_TextView);
textView.setText(element.getCode());
textView.setMovementMethod(ScrollingMovementMethod
.getInstance());
textView.setHorizontallyScrolling(true); // 不让超出屏幕的文本自动换行,使用滚动条
textView.setFocusable(true);
这样就OK了。
相关文章推荐
- TextView取消自动换行并设置水平滚动
- Android textview和listview实现水平自动滚动的走马灯效果
- android中TextView中如何设置水平滚动效果
- android中TextView中如何设置水平滚动效果
- android中TextView中如何设置水平滚动效果
- adnroid textview设置文字横向自动滚动(跑马灯效果)
- android中TextView中如何设置水平滚动效果
- TextView设置文字包含中英文时自动换行问题的终极解决方案
- android 设置TextView水平滚动和解决首行缩进问题
- android中TextView中如何设置水平滚动效果
- Android TextView 自动换行问题
- android实现TextView垂直或水平滚动
- android TextView 自动换行
- [MFC]RichEdit响应回车换行,自动水平/垂直滚动
- Android TextView文字横向自动滚动(跑马灯)
- TextView 实现自动换行(转)
- 解决TextView排版自动换行问题
- Android TextView 自动换行问题(zz)
- 让TextView上显示的文字(文字过多时)能够水平滚动显示
- 解决Android的TextView不能自动换行的问题