加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 教程 > 正文

Android组件TextView达成字体水平滚动

发布时间:2021-11-24 18:08:56 所属栏目:教程 来源:互联网
导读:字体滚动 [功能] 当字太多的话 让字体滚动 会是一个好办法 [代码 步骤] 1. 设定 TextView 的属性 ?xml version=1.0 encoding=utf-8? RelativeLayout xmlns:Android=http://schemas.android.com/apk/res/android xmlns:app=http://schemas.android.com/apk/res
字体滚动
 
[功能]
 
当字太多的话 让字体滚动 会是一个好办法
 
[代码 步骤]
 
1. 设定 TextView 的属性
 
<?xml version="1.0" encoding="utf-8"?>   
<RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
        xmlns:app="http://schemas.android.com/apk/res/com.android.View.CustomView"  
        android:orientation="vertical"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content">   
<TextView   
    android:id="@+id/text"  
    android:layout_width="100px"  
    android:layout_height="wrap_content"  
       
                //居中显示   
    android:layout_centerInParent="true"  
       
                //使得字不分行显示 否则当字太多会分行   
    android:singleLine="true"  
       
    android:layout_x="61px"  
    android:layout_y="69px"  
  
                //设置为"滚动"   
    android:ellipsize="marquee"  
                   
                //设置滚动时间为永远 也可以为具体的int 来设置滚动次数   
    android:marqueeRepeatLimit="marquee_forever"  
/>   
</RelativeLayout>  
2. 给 TextView 指定显示内容
 
public class TextGoUsage extends Activity {   
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);   
        setContentView(R.layout.main);   
           
        TextView text = (TextView) findViewById(R.id.text);   
        text.setText("梅花绝句 闻道梅花坼晓风 雪堆遍满四山中 何方可化身千亿 一树梅花一放翁");   
        text.setTextSize(30);   
        text.setFocusable(true);   
    }   
}  
3. emulator 运行效果  2次时间的截图:
 
 
 
 
 
 
 
done!

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读