现在的位置: 首页 > 综合 > 正文

字体水平滚动

2018年03月20日 ⁄ 综合 ⁄ 共 1532字 ⁄ 字号 评论关闭

字体水平滚动 http://griffinshi.iteye.com/blog/585791

文字垂直滚动 http://griffinshi.iteye.com/blog/599015

字体滚动

 

[功能]

当字太多的话 让字体滚动 会是一个好办法

 

 

[代码 步骤]

1. 设定 TextView 的属性

Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.         xmlns:app="http://schemas.android.com/apk/res/com.android.View.CustomView"  
  4.         android:orientation="vertical"  
  5.         android:layout_width="fill_parent"  
  6.         android:layout_height="wrap_content">  
  7. <TextView  
  8.     android:id="@+id/text"  
  9.     android:layout_width="100px"  
  10.     android:layout_height="wrap_content"  
  11.       
  12.                 //居中显示  
  13.     android:layout_centerInParent="true"  
  14.       
  15.                 //使得字不分行显示 否则当字太多会分行  
  16.     android:singleLine="true"  
  17.       
  18.     android:layout_x="61px"  
  19.     android:layout_y="69px"  
  20.   
  21.                 //设置为"滚动"  
  22.     android:ellipsize="marquee"  
  23.                   
  24.                 //设置滚动时间为永远 也可以为具体的int 来设置滚动次数  
  25.     android:marqueeRepeatLimit="marquee_forever"  
  26. />  
  27. </RelativeLayout>  

 

2. 给 TextView 指定显示内容

Java代码  收藏代码
  1. public class TextGoUsage extends Activity {  
  2.     /** Called when the activity is first created. */  
  3.     @Override  
  4.     public void onCreate(Bundle savedInstanceState) {  
  5.         super.onCreate(savedInstanceState);  
  6.         setContentView(R.layout.main);  
  7.           
  8.         TextView text = (TextView) findViewById(R.id.text);  
  9.         text.setText("梅花绝句 闻道梅花坼晓风 雪堆遍满四山中 何方可化身千亿 一树梅花一放翁");  
  10.         text.setTextSize(30);  
  11.         text.setFocusable(true);  
  12.     }  
  13. }  

 

 

3. emulator 运行效果  2次时间的截图:

 

 

 

done!

 

抱歉!评论已关闭.