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. Jpa 语法和 demo

    转 http://www.cnblogs.com/jiangxiaoyaoblog/p/5635152.html 参考资料   https://www.w3cschool.cn/java/jpa-qu ...

  2. mysql 批量更新常用操作

    mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下: UPDATE mytable SET myfield = 'value' WHERE other_field = ' ...

  3. rubygems ruby国内源

    rubygems.org资源不能正常访问,需要调整一下GEM的source镜像 1.首先确认一下当前source镜像地址 gem sources -l 服务器为 https://    ruby    ...

  4. [k8s]k8s 1.9(on the fly搭建) 1.9_cni-flannel部署排错 ipvs模式

    角色 节点名 节点ip master n1 192.168.14.11 节点1 n2 192.168.14.12 节点2 n3 192.168.14.13 https://raw.githubuser ...

  5. [na]二层+tcp/udp数据包格式

    标准:6+6+2+3    =17            3 思科:6+6+2+3+3=20           6 ip首部格式 tcp首部格式

  6. 【Android】5.6 弹出菜单(PopUp Menus)

    分类:C#.Android.VS2015: 创建日期:2016-02-07 一.简介 功能描述:用户单击按钮弹出菜单.当用户选择一个菜单项,会触发MenuItemClick事件并让弹出的菜单消失:如果 ...

  7. HDU 4952 Poor Mitsui(贪心)

    HDU 4957 Poor Mitsui pid=4957" style="">题目链接 思路:利用相邻交换法去贪心就可以.注意容积为0的情况,这是个坑点 代码: ...

  8. 2>/dev/null

    2>/dev/null是如果你的命今出错的话,错误报告直接输出到黑洞里不会显示在屏幕上. ls -al 1>list.txt 2>list.err #将显示的数据,正确的输出到lis ...

  9. spark结构化数据处理:Spark SQL、DataFrame和Dataset

    本文讲解Spark的结构化数据处理,主要包括:Spark SQL.DataFrame.Dataset以及Spark SQL服务等相关内容.本文主要讲解Spark 1.6.x的结构化数据处理相关东东,但 ...

  10. UBoot启动代码第一阶段流程

    http://blog.csdn.net/xautfengzi/article/details/7470134 前段时间了看了UBoot的源码,放了一段时间之后忘得差不多了.现做一些注释,方便以后温习 ...