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文本中文字 ...
随机推荐
- Python入门--20--类、对象
OO=Object Oriented 面向对象 python是面向对象的编程语言 OO的特征: 1.封装:把一堆东西都扔到一起,变为一个类 2.继承:假如一个类里面 3.多态:不同的类有相同名称的函数 ...
- Linux 之 文件内容查看
文件内容查看 参考教程:[千峰教育] 文件内容查看: cat: 作用:一次性顺序显示文件的所有内容 格式:cat file tac: 作用:一次性倒序显示文件的所有内容 格式:tac file hea ...
- Drupal 有用的模块
投票模块drigg https://www.drupal.org/project/drigg
- AC日记——Count on a tree bzoj 2588
Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始 ...
- Java 内存查看与分析
1:gc日志输出 在jvm启动参数中加入 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimestamps -XX:+PrintGCApplication ...
- Software Engineering | UML
六大关系:关联association.依赖dependency.聚合aggregation.组合compositon.泛化generalization.实现realization. 盗图: 关联:关联 ...
- OS | Socket
TCP 创建socket: int socket(int domain, int type, int protocol); AF = Address FamilyPF = Protocol Famil ...
- TDDL-剖析淘宝TDDL
TDDL-剖析淘宝TDDL 学习了:https://blog.csdn.net/sumj7011/article/details/78286741 Taobao Distribute Data Lay ...
- [c++菜鸟]《Accelerate C++》读书笔记
第0章 开始学习C++ 1.<<的行为取决于它的操作数类型,<<会把它的右操作数的字符写到左操作数所指示的流中,他是结果就是它的左操作数. 2.std::endl是一个控制器, ...
- JMeter 压力測试使用函数和 CSV 文件參数化 json 数据
在 http Load Testing 中.json 数据的提交是个让人头疼的问题.本文具体介绍怎样进行 JMeter 的 json 測试提交,以及怎样将其參数化. St ...