1.写一个类继承TextView

  1. package com.example.tt;
  2. import android.content.Context;
  3. import android.graphics.Rect;
  4. import android.util.AttributeSet;
  5. import android.widget.TextView;
  6. public class ScrollingTextView extends TextView {
  7. public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
  8. super(context, attrs, defStyle);
  9. }
  10. public ScrollingTextView(Context context, AttributeSet attrs) {
  11. super(context, attrs);
  12. }
  13. public ScrollingTextView(Context context) {
  14. super(context);
  15. }
  16. @Override
  17. protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
  18. if(focused)
  19. super.onFocusChanged(focused, direction, previouslyFocusedRect);
  20. }
  21. @Override
  22. public void onWindowFocusChanged(boolean focused) {
  23. if(focused)
  24. super.onWindowFocusChanged(focused);
  25. }
  26. @Override
  27. public boolean isFocused() {
  28. return true;
  29. }
  30. }

2.xml 中增加属性

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <com.example.tt.ScrollingTextView
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_marginLeft="80dip"
  11. android:layout_marginBottom="25dip"
  12. android:textSize="25sp"
  13. android:singleLine="true"
  14. android:textColor="@android:color/black"
  15. android:ellipsize="marquee"
  16. android:focusable="true"
  17. android:marqueeRepeatLimit="marquee_forever"
  18. android:focusableInTouchMode="true"
  19. android:scrollHorizontally="true"
  20. android:text="这才是真正的文字跑马灯效果,文字移动速度,文字移动方向,文字移动的样式,动画等等……"
  21. android:background="#2FFFFFFF" />
  22. <Button
  23. android:id="@+id/button1"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:text="Button" />
  27. </LinearLayout>

3. 在activity中声明

    1. package com.example.tt;
    2. import android.os.Bundle;
    3. import android.app.Activity;
    4. import android.view.Menu;
    5. public class MainActivity extends Activity {
    6. @Override
    7. public void onCreate(Bundle savedInstanceState) {
    8. super.onCreate(savedInstanceState);
    9. setContentView(R.layout.activity_main);
    10. }
    11. }

TextView不用获取焦点也能实现跑马灯的更多相关文章

  1. 自定义TextView跑马灯

    本篇主要介绍TextView的可控制跑马灯效果实现. Android自带的TextView添加几个属性就可以实现跑马灯效果,大概是这样 android:ellipsize="marquee& ...

  2. 【Android】TextView跑马灯效果

    老规矩,先上图看效果. 说明 TextView的跑马灯效果也就是指当你只想让TextView单行显示,可是文本内容却又超过一行时,自动从左往右慢慢滑动显示的效果就叫跑马灯效果. 其实,TextView ...

  3. 跑马灯带你深入浅出TextView的源码世界

    一.背景 想必大家平时也没那么多时间是单独看源码,又或者只是单纯的看源码遇到问题还是不知道怎么从源码的角度解决. 但是大家平时开发过程中肯定会遇到这样或那样的小问题,通过百度.Google搜索都无果, ...

  4. Android:TextView文字跑马灯的效果实现

    解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...

  5. Android中TextView不获取焦点可以实现跑马灯的效果

    之前在网上找了很多关于TextView的跑马灯效果实现的例子,实现起来都存在一些问题,例如一种是完全重画一个跑马灯,还有就是只设置TextView的相关属性使其具有跑马灯的效果,总的来说这两种方法都是 ...

  6. ListView 中的TextView实现跑马灯效果

    案例:怎么样在一个ListView中含有TextView的item中实现字母滚动呢.这个在一些特定的场合经常用得到.如下图,当焦点位于某个item的时候其内容就自动滚动显示 要实现这样的效果,废话不多 ...

  7. Android成长日记-仿跑马灯的TextView

    在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢? ----------------------------------- ...

  8. Android:TextView 自动滚动(跑马灯) (转)

    Android:TextView 自动滚动(跑马灯)       TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...

  9. TextView实现跑马灯效果

    网上有很多跑马灯的介绍,有很多跑马灯的代码.或许我的不是最好的,但是应该很容易明白的. 我们先来介绍一个跑马灯的代码 <LinearLayout xmlns:android="http ...

随机推荐

  1. 【转】使用create_project.py创建cocos2d项目时出错

    命令格式:create_project.py -project 项目名字 -package 包名 -language cpp,例如: create_project.py -project HelloC ...

  2. IT人都非常忙(茫)

    我发现.身边的盆友都非常忙,要么在加班.要么加班刚回家:要么在出差,要么刚出差回来. 难道搞IT的人都非常忙么?忙还是茫? 大学期间.不知道未来要干什么.非常多人也不清楚应该学习哪些知识和技能.是否须 ...

  3. yum 报错 Error: rpmdb open failed

    # yum list rpmdb: unable to join the environment error: db3 error() from dbenv->open: Resource te ...

  4. zookeeper 大量连接断开重连原因排查

    转自:http://blog.csdn.net/hengyunabc/article/details/41450003?utm_source=tuicool&utm_medium=referr ...

  5. 九、Null在Java中的精确表示

    让我们从下面的语句开始: String x = null; 1.           这个语句具体的做了什么? 回一下什么是变量和什么是值.通常的比喻是变量类似于一个盒子. 就像你可以用盒子来存储东西 ...

  6. mysql show full processlist

    processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1. 进入mysql/bin目录下输入mysqladmin -u -p -h127. ...

  7. string 与 char 的区别

    1.char是字符类型 2.string是字符串类型 虽然一字之差,但其本质是很大的. 1. char属于基础类型(C++),在C#中它属于值类型(Value Type).char类型的长度是固定的, ...

  8. 关联容器——map、set

    map类型通常被称为关联数组,与正常数组类似,不同之处在于其下标不必是整数.我们通过一个关键字而不是位置来查找值(键值对). 与之相对,set就是关键字的简单集合.当只是想知道一个值是否存在时,set ...

  9. 教程-TObjectList.Clear、TStringList.Clear方法对象有没有被释放

    相关资料: http://www.cnblogs.com/rogge7/p/4631796.html delphiTStringList通过AddObject方法添加对象. object里存的只是指向 ...

  10. [uart]理解线路规程的作用

    转自:http://biancheng.dnbcw.info/linux/336240.html Linux OS的设备驱动有相当经典的抽象思想以及分层思想.与通信世界里面的思想相一致. 一.在Lin ...