TextView实现跑马灯效果

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用

使用TextView简单实现灯箱跑马灯效果:

直接上代码:activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        tools:context="com.example.t.MainActivity" >  
      
        <TextView  
            android:id="@+id/notice"  
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent"  
            android:ellipsize="marquee"//以横向滚动方式显示(需获得当前焦点时)  
            android:focusable="true"//允许获取焦点  
            android:focusableInTouchMode="true"//设置是否触摸模式。  
            android:gravity="center"  
            android:marqueeRepeatLimit="marquee_forever"//一直滚动  
            android:scrollHorizontally="true"//设置文本超出TextView长度的情况下,是否出现横拉条  
            android:singleLine="true"//单行显示  
            android:textSize="20sp"  
            android:textColor="#FF0000"  
            android:text="回收二手航母、导弹、潜艇、坦克、翻新原子弹啦!!!!..."  
            android:textStyle="bold" />  
      
    </RelativeLayout>  

JAVA代码:MainActivity.java
    package com.example.t;  
      
    import android.app.Activity;  
    import android.os.Bundle;  
    import android.view.Menu;  
    import android.view.MenuItem;  
    import android.view.Window;  
      
    public class MainActivity extends Activity {  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            requestWindowFeature(Window.FEATURE_NO_TITLE);//无标题  
            setContentView(R.layout.activity_main);  
        }  
      
        @Override  
        public boolean onCreateOptionsMenu(Menu menu) {  
            // Inflate the menu; this adds items to the action bar if it is present.  
            getMenuInflater().inflate(R.menu.main, menu);  
            return true;  
        }  
      
        @Override  
        public boolean onOptionsItemSelected(MenuItem item) {  
            // Handle action bar item clicks here. The action bar will  
            // automatically handle clicks on the Home/Up button, so long  
            // as you specify a parent activity in AndroidManifest.xml.  
            int id = item.getItemId();  
            if (id == R.id.action_settings) {  
                return true;  
            }  
            return super.onOptionsItemSelected(item);  
        }  
    }  

标签: 代码

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:struts2 文件下载

下一篇:Struts2 多文件上传