• android实现跑马灯效果


    第一步:新建一个新项目,MarqueeTextView
    首先为了观察到跑马灯效果,将要显示的文字极可能 写长。在strings.xml目录里面将

    <string name="hello_world">hello_world</string>

    改动为

    <string name="hello_world">我的代码非常长,真的非常长,不行你看看。实际上是骗你的,逗比,hiahia~~~~</string>

    默认情况下。显示文字会自己主动换行!为了实现跑马灯效果。首先要阻止其自己主动换行。通过使用singleLine属性来实现!
    android:singleLine=”true”
    假设其目的不过实现单行文字的跑马灯效果。能够只再通过三个语句来实现!
    android有个ellipsize属性。
    android:ellipsize=”marquee”
    android:focusable=”true”
    android:focusableInTouchMode=”true”

    通过上述代码能够实现单行文字的跑马灯效果。可是假设要实现多行文字的跑马灯效果,将上述代码反复书写,不能实现预想功能!

    由于在上述的focusable属性里面已经将焦点定义到第一行上!兴许的得不到focus!

    能够通过新建一个class类来实现!

    在src目录里面新建一个类命名为MarqueeText

    package com.example.marqueetextviewdemo1;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    public class MarqueeText extends TextView{
    
        public MarqueeText(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
    
        public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            // TODO Auto-generated constructor stub
        }
    
        public MarqueeText(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
        }
        public boolean isFocused() {
            return true;
        }
    }

    然后再将main.xml文件中面的TextView所有改动为 包名+.+类名。
    此次改动是为了将所有以这样的方式定义的,都能获得focus。然后实现跑马灯的效果!

    显示的效果例如以下:
    这里写图片描写叙述

  • 相关阅读:
    Python并发编程:协程-greenlet模块
    Python并发编程:协程介绍
    Python并发编程:多线程-进程池与线程池
    Python并发编程:多线程-线程queue
    程序员能力矩阵(好到这个好有压力...)
    如何让搜索引擎抓取AJAX内容? 转
    使用ReSharper打造团队代码检查流程
    JQuery Easy Ui dataGrid 数据表格 -->转
    TCP/IP协议(1):各层协议帧格式
    VC调试小结
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7263415.html
Copyright © 2020-2023  润新知