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 ...
随机推荐
- 模拟HTTP请求获取返回值
package org.jeecgframework.core.util; import java.io.BufferedReader; import java.io.IOException; imp ...
- wavwrite注意事项
前几天群里有人提出一个问题:MATLAB里,同样频率的信号写入/读取,为什么频率感觉不同? 测试code: fs = 2000; f0 = 20; t = 0:1/fs:1; subplot 211 ...
- Angularjs 控制器controller的作用
我们在view中给模型的一个参数name赋值 “hello world” . 这是一种简单的赋值,我们可以在视图中通过 ng 指令(以ng-开头的指令)实现了简单的赋值,如果遇到复杂的逻辑运算操作,那 ...
- Flume入门
1.Flume是什么? ○ Flume是由cloudera开发的实时日志收集系统 ○ 核心概念是由一个叫做Agent(代理节点)的java进程运行在日志收集节点 ○ Flume在0.94. ...
- 使用jQuery的ajax同步请求吃过的亏
jQuery是一个非经常常使用的js库.甚至我们开发不论什么一个项目都首先把jquery导入进行.jQuery太过强大,使用起来非常方便.可是在使用的过程中也遇到过非常多坑.我在这里分享一下.避免大家 ...
- BZOJ 1029 JSOI2007 建筑抢修 贪心+堆
题目大意:n个建筑须要抢修.第i个建筑须要T1时间抢修.必须在T2时间之前抢修完成.求最多能抢修多少建筑 首先我们对T2排序 然后依次修理 可是这样贪心显然是不对的 比方说这组数据: 5 10 10 ...
- js检查页面上有无重复id的代码分享
用js代码检查一个页面上是否用重复的id. 方法一: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ...
- 【Android】7.8 MyDemos项目的结构和主界面相关代码
分类:C#.Android.VS2015: 创建日期:2016-02-17 一.简介 上一讲已经说过,系统升级为Win10后,重新创建了一个新的项目:MyDemos,并把前7章合并到了这个项目中,这次 ...
- BestCoder Round #4 Miaomiao's Geometry (暴力)
Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...
- nyoj123 士兵杀敌(四)树状数组 插线问点
士兵杀敌(四) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 南将军麾下有百万精兵,现已知共有M个士兵,编号为1~M,每次有任务的时候,总会有一批编号连在一起人请战(编 ...