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. 清理linux 某个文件夹下面所有的log文件

    #!/bin/sh #目标文件夹下面所有问题 target_dir="/app/" #删除2天前新建的后缀为log的文件 -name "*.log" -exec ...

  2. jquery.dataTables的用法

    写页面前端时,使用表格的插件可以快速漂亮的排版.本例子中使用jquery.dataTables来处理table.直接来点干货 html代码如下 <table cellpadding=" ...

  3. js innerHTML 改变div内容的方法

    永远不知道你可以改变的内容,一个HTML元素?也许你要取代的文字段落中,以反映什么访客选定刚刚从下拉框中.通过操纵一个元素的innerHtml您可以变更您的文本和HTML多达你喜欢.改变文字inner ...

  4. 使用vim-latex排版

    前几天在某个群上看到了一篇简历,内容不重要,一看排版很漂亮的说.一问才知道是用latex排版工具排版的.一想到我都大三下学期的,也快大四了,是不是要准备一份简历.于是就想使用latex这个排版工具来排 ...

  5. mogoose的bug之不能根据类型为number的字段查找数据

    Users.find({paw:6868}).exec() //返回的结果为空 Users.find({paw:"6868"}).exec() //返回的结果也为空 Users.f ...

  6. ubantu 文件解压缩

    对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Windows下最常见 的压缩文件就只有两种,一是,zip,另一个是.rar. ...

  7. 每日英语:Some Chinese Students Stay Home to Get Ahead

    Li Shan's oldest son was the perfect candidate to join the throngs of Chinese students studying abro ...

  8. Ubuntu 12.04下jdk的安装与配置

    由于要开始在linux下学习jsp的开发,所以就准备自己动手配置一下jdk和tomcat jdk 下载地址: http://www.oracle.com/technetwork/java/javase ...

  9. iOS使用webView加载HTML网页链接简单展示

    //网页视图 _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 64, mWidth, mHeight-64)]; _webView.d ...

  10. 实际应用中的C#加密

    在系统的管理员有着实际的应用,对于一个数据库管理系统来说,数据库安全还是挺重要的,所以在存入到数据库的密码通常都是加密的.即使有着hack攻破数据库后,也不会那样的容易的盗取你的账号和密码,这样可以减 ...