您的位置:首页 > 其它

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了。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: