TextView不用获取焦点也能实现跑马灯
1.写一个类继承TextView
- package com.example.tt;
- import android.content.Context;
- import android.graphics.Rect;
- import android.util.AttributeSet;
- import android.widget.TextView;
- public class ScrollingTextView extends TextView {
- public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- public ScrollingTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public ScrollingTextView(Context context) {
- super(context);
- }
- @Override
- protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
- if(focused)
- super.onFocusChanged(focused, direction, previouslyFocusedRect);
- }
- @Override
- public void onWindowFocusChanged(boolean focused) {
- if(focused)
- super.onWindowFocusChanged(focused);
- }
- @Override
- public boolean isFocused() {
- return true;
- }
- }
2.xml 中增加属性
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <com.example.tt.ScrollingTextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="80dip"
- android:layout_marginBottom="25dip"
- android:textSize="25sp"
- android:singleLine="true"
- android:textColor="@android:color/black"
- android:ellipsize="marquee"
- android:focusable="true"
- android:marqueeRepeatLimit="marquee_forever"
- android:focusableInTouchMode="true"
- android:scrollHorizontally="true"
- android:text="这才是真正的文字跑马灯效果,文字移动速度,文字移动方向,文字移动的样式,动画等等……"
- android:background="#2FFFFFFF" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Button" />
- </LinearLayout>
3. 在activity中声明
- package com.example.tt;
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- public class MainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- }
TextView不用获取焦点也能实现跑马灯的更多相关文章
- 自定义TextView跑马灯
本篇主要介绍TextView的可控制跑马灯效果实现. Android自带的TextView添加几个属性就可以实现跑马灯效果,大概是这样 android:ellipsize="marquee& ...
- 【Android】TextView跑马灯效果
老规矩,先上图看效果. 说明 TextView的跑马灯效果也就是指当你只想让TextView单行显示,可是文本内容却又超过一行时,自动从左往右慢慢滑动显示的效果就叫跑马灯效果. 其实,TextView ...
- 跑马灯带你深入浅出TextView的源码世界
一.背景 想必大家平时也没那么多时间是单独看源码,又或者只是单纯的看源码遇到问题还是不知道怎么从源码的角度解决. 但是大家平时开发过程中肯定会遇到这样或那样的小问题,通过百度.Google搜索都无果, ...
- Android:TextView文字跑马灯的效果实现
解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...
- Android中TextView不获取焦点可以实现跑马灯的效果
之前在网上找了很多关于TextView的跑马灯效果实现的例子,实现起来都存在一些问题,例如一种是完全重画一个跑马灯,还有就是只设置TextView的相关属性使其具有跑马灯的效果,总的来说这两种方法都是 ...
- ListView 中的TextView实现跑马灯效果
案例:怎么样在一个ListView中含有TextView的item中实现字母滚动呢.这个在一些特定的场合经常用得到.如下图,当焦点位于某个item的时候其内容就自动滚动显示 要实现这样的效果,废话不多 ...
- Android成长日记-仿跑马灯的TextView
在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢? ----------------------------------- ...
- Android:TextView 自动滚动(跑马灯) (转)
Android:TextView 自动滚动(跑马灯) TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...
- TextView实现跑马灯效果
网上有很多跑马灯的介绍,有很多跑马灯的代码.或许我的不是最好的,但是应该很容易明白的. 我们先来介绍一个跑马灯的代码 <LinearLayout xmlns:android="http ...
随机推荐
- mysql 表锁——读锁和写锁
注意, 0.表的索引类型必须是InnoDB.相关链接:http://www.cnblogs.com/CyLee/p/5579672.html 1.如果你使用Navicat Premium,有可能会出现 ...
- [Python]南邮OJ代码备份爬虫
之前看过Python学习的经验,说以project为导向学习. 自己分析了一下,一般接触Python的都有一定的其它语言基础,对于程序设计的基本逻辑,语法都有一个大概的了解.而Python这样的脚本语 ...
- Android:EditText 属性
Android开发EditText属性 EditText 官网链接 EditText继承关系:View-->TextView-->EditText EditText 部分属性: XML 设 ...
- documentdb
https://azure.microsoft.com/en-us/services/documentdb/ https://www.simple-talk.com/cloud/cloud-data/ ...
- ARM GNU常用汇编语言介绍
ARM GNU常用汇编语言介绍 ARM汇编语言源程序语句,一般由指令,伪操作,宏指令和伪指令组成. ARM汇编语言的设计基础是汇编伪指令,汇编伪操作和宏指令. 伪操作,是ARM汇编语言程序里的一些特殊 ...
- sql server 递归汇总 按指定层级汇总
每个地区递归层级可能不一致,数据表(table)存放最小层级地区 area --地区层级表 id name f_id leve 1 中国 0 1 2 湖北 1 2 3 武汉 2 3 ... --测试数 ...
- 文件io之——open/close
一个进程默认打开三个文件描述符: STDIN_FILENO 0STDOUT_FILENO 1STDERR_FILENO 2 man 2 open可查看详情: open函数可以打开或者创建一个文件: # ...
- discuz论坛折腾记录
1.邮箱验证 自带的是用php sendmail,好在可以用smtp 如果用企业邮箱,一般都是ssl,需要设置为,参考此帖 STMP服务器 - QQ 企业邮ssl://smtp.exmail.qq.c ...
- pdo_mysql安装
如果编译时没有编译pdo模块,可以cd 到php编译时的目录,重新编译 1.切换到pdo_mysql目录,如php-5.5.10/ext/pdo_mysql/ 2.生成configure文件,在pdo ...
- C#基础-获得当前程序的 空间名.类名.方法名
string typeName = this.GetType().ToString();//空间名.类名 string typeName = this.GetType().Name;//类名 new ...