android实现跑马灯效果
第一步:新建一个新项目,MarqueeTextView
首先为了观察到跑马灯效果,将要显示的文字极可能 写长。在strings.xml目录里面将
<string name="hello_world">hello_world</string>
改动为
<string name="hello_world">我的代码非常长,真的非常长,不行你看看。实际上是骗你的,逗比,hiahia~~~~</string>
默认情况下。显示文字会自己主动换行!为了实现跑马灯效果。首先要阻止其自己主动换行。通过使用singleLine属性来实现!
android:singleLine=”true”
假设其目的不过实现单行文字的跑马灯效果。能够只再通过三个语句来实现!
android有个ellipsize属性。
android:ellipsize=”marquee”
android:focusable=”true”
android:focusableInTouchMode=”true”
通过上述代码能够实现单行文字的跑马灯效果。可是假设要实现多行文字的跑马灯效果,将上述代码反复书写,不能实现预想功能!
由于在上述的focusable属性里面已经将焦点定义到第一行上!兴许的得不到focus!
能够通过新建一个class类来实现!
在src目录里面新建一个类命名为MarqueeText
package com.example.marqueetextviewdemo1;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MarqueeText extends TextView{
public MarqueeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public boolean isFocused() {
return true;
}
}
然后再将main.xml文件中面的TextView所有改动为 包名+.+类名。
此次改动是为了将所有以这样的方式定义的,都能获得focus。然后实现跑马灯的效果!
显示的效果例如以下:
android实现跑马灯效果的更多相关文章
- android实现跑马灯效果(能够实现两个以上跑马灯)
本文用了继承自TextView的MarqueeTextView来实现跑马灯效果.原因是,跑马灯效果是须要TextView拥有焦点才会跑动的.而有时候TextView获得焦点会有点耗时,造成要等待一段时 ...
- Android单行跑马灯效果实现
参考网址:https://www.jianshu.com/p/e6c1b825d322 起初,使用了如下XML布局: <TextView android:id="@+id/tv_per ...
- Android TextView 跑马灯效果 - 2018年6月19日
第一步在布局中添加加粗部分代码: <TextView android:id="@+id/tv_company" android:layout_width="0dp& ...
- Android中跑马灯效果
<com.randy.test1.self.MarqueeText android:id="@+id/btn1" android:layout_width="mat ...
- Android 开发笔记___textvieww__跑马灯效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- android 怎么实现跑马灯效果
自定义控件 FocusedTextView, 使android系统误以为它拥有焦点 public class FocusedTextView extends TextView { public Foc ...
- 安卓之文本视图TextView及跑马灯效果
一.基本属性和设置方法 二.跑马灯用到的属性与方法说明 三.省略方式的取值说明 四.跑马灯效果案例代码 (1)布局xml文件 <?xml version="1.0" en ...
- 在android中用跑马灯的效果显示textview
大家好,在我们通常的android project中,通常需要用到textview这一个布局文件,并且对于这一个显示布局所需要的文本文字内容. 下面我们就来介绍一种方法来实现在android中用跑马灯 ...
- android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习
跑马灯效果 1.用过属性的方式实现跑马灯效果 属性: android:singleLine="true" 这个属性是设置TextView文本中文字 ...
随机推荐
- 汇编指令详解--as手册
https://sourceware.org/binutils/docs/as/ Table of Contents 1 Overview 1.1 Structure of this Manual 1 ...
- 论epoll的实现
论epoll的实现 上一篇博客 论select的实现 里面已经说了为什么 select 比较慢.poll 的实现和 select 类似,只是少了最大 fd 限制,如果有兴趣可以自己去看代码.我这里来简 ...
- LeetCode OJ--Merge Sorted Array *
http://oj.leetcode.com/problems/merge-sorted-array/ 两个有序数组A和B的归并排序,将结果存到A中.因为已知两数组长度且A的数组足够大,所以倒着处理, ...
- Codeforces 946 C.String Transformation
C. String Transformation time limit per test 1 second memory limit per test 256 megabytes input st ...
- LaTeX 如何在文档的侧面插入图片实现"绕排"?
https://www.zhihu.com/question/26837705 https://blog.csdn.net/u012856866/article/details/70305834
- 两种const函数
有两种const函数,声明如下:1.const T func();2.T func() const;第一种表示返回的是const的类型,也即返回的值不能作为左值,楼主懂的.第二种表示该成员函数不能修改 ...
- bzoj 3328 : PYXFIB
Discription Input 第一行一个正整数,表示数据组数据 ,接下来T行每行三个正整数N,K,P Output T行,每行输出一个整数,表示结果 Sample Input 1 1 2 3 S ...
- Cursor类用法:
Cursor类用法: http://www.2cto.com/kf/201109/103163.html Ctrl+Shift+G 查找类.方法和属性的引用.这是一个非常实用的快捷键,例如 ...
- 验证loadrunner对Ajax内容的校验
前一阵和开发的同事一起測试某个系统的性能.此系统是发送Ajax请求到后台,再调用第三方的某项服务. 第三方服务的性能由不得我们控制.因此开发者做了一下改进.超时则直接返回. 于是在loadrunner ...
- 教你使用 Reflexil 反编译.NET
简介 反编译的方式有很多种,其实最靠谱的还是IL反编译. 如果不懂IL可以尝试我这边文章入门:http://www.wxzzz.com/278.html 不过我下面要说的不是IL这种底层的代码反编译, ...