android TextView实现滚动显示效果
在android中,如果设置了TextView控件为单行显示,且显示的文本太长的话,默认情况下会造成显示不全的情况,这种情况下我们需要设置该控件属性如下:
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world"
/>
package com.example.administrator.test_hello_world;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Created by Administrator on 2016/3/17.
* 实现跑马灯效果的TextView
*/
public class marqueeText extends TextView {
public marqueeText(Context context) {
super(context);
}
public marqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public marqueeText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
//返回textview是否处在选中的状态
//而只有选中的textview才能够实现跑马灯效果
@Override
public boolean isFocused() {
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!--singleLine只能是单行显示-->
<com.example.administrator.test_hello_world.marqueeText
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world"
/>
<com.example.administrator.test_hello_world.marqueeText
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world"
/>
</LinearLayout>
package com.example.administrator.test_hello_world;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
void init_view() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
init_view();
}
}
android TextView实现滚动显示效果的更多相关文章
- Android:TextView 自动滚动(跑马灯) (转)
Android:TextView 自动滚动(跑马灯) TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...
- Android TextView 横向滚动(跑马灯效果)
Android TextView 中当文字比較多时希望它横向滚动显示,以下是一种亲測可行的方法. 效果图: 1.自己定义TextView,重写isFocused()方法返回true,让自己定义Text ...
- android TextView 垂直滚动 用动画实现
项目中需要让TextView 滚动一会显示一行一会显示一行 想了下用移动动画实现.但是实际中在整这个动画时调了好久.主要用到的动画方式是移动动画:TranslateAnimation 代码: PS: ...
- Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果
一:如何自定义TextView实现滚动效果 继承TextView基类 重写构造方法 修改isFocused()方法,获取焦点. /* * Copyright (C) 2015 The Android ...
- android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)
本来是想做一个显示文字信息的,当文字很多时View的高度不能超过一个固定的值,当文字很少时View的高度小于那个固定值时,按View的高度显示.因为ScrollView没有maxHeight,无法满足 ...
- Android TextView 添加下划线的几种方式
总结起来大概有5种做法: 1. 将要处理的文字写到一个资源文件,如string.xml(使用html用法格式化) 2. 当文字中出现URL.E-mail.电话号码等的时候,可以将TextView ...
- Android TextView图文混合编排
Android TextView图文混合编排 实现技术细节不难,两个要点:1.html代码的混合编写.2,重写ImageGetter.例如:布局: <?xml version="1.0 ...
- android Textview动态设置大小
import android.app.Activity; //import com.travelzen.tdx.BaseActivity; //import com.travelzen.tdx.uti ...
- Android TextView内容过长加省略号,点击显示全部内容
在Android TextView中有个内容过长加省略号的属性,即ellipsize,用法如下: 在xml中:android:ellipsize="end" 省略号在结尾an ...
随机推荐
- Android Stduio的使用(七)--Structure窗口
1.本篇博文介绍Android查看.Java文件中所有属性和类方法的工具:Structure窗口 2.我们知道Eclipse的OutLine窗口可以查看.java文件所有的属性和方法. 2.Andro ...
- svn up 提示:Skipped '.'
>svn up Skipped '.' >svn cleanup '.' is not a working copy directory >svn co https://192.16 ...
- CGI接口原理及实现(转载)
原文:http://blog.csdn.net/duola_rain/article/details/15812585 CGI接口原理及实现(2012-12-7 Over) 1.CGI定义: CGI( ...
- 黄聪:基于Asp.net的CMS系统We7架设实验(环境WIN7,SQL2005,.NET3.5)(初学者参考贴)
http://www.cnblogs.com/huangcong/archive/2010/03/30/1700348.html
- Android--->Button按钮操作
main.xml中设置两个按钮 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xm ...
- 转:Web测试需要了解的知识
这里只是介绍Web测试相对于其他类型软件的测试额外需要了解的内容,关于测试方法不是本文的重点,里面谈到的每一项在以后的文章中再说明.大家看到这些内容可能都不陌生,我晒出的内容也许不对或有误导,请大家指 ...
- PAT (Advanced Level) 1077. Kuchiguse (20)
最长公共后缀.暴力. #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
- POJ 3648 Wedding
2-SAT,直接选择新娘一侧的比较难做,所以处理的时候选择新郎一侧的,最后反着输出就可以. A和B通奸的话,就建边 A->B'以及B->A’,表示 A在新郎一侧的话,B一定不在:B在新郎一 ...
- N层架构实现的一个小例子
主要用到了[单例,抽象工厂,缓存,N层,反射]等知识.架构图如下: 解决方案用到的项目列表如下: 在接口项目中,定义一个IUER接口. namespace IDAL { public interfac ...
- shell命令前后端切换和暂停
Shell支持作用控制,有以下命令: 1. command& 让进程在后台运行 2. jobs 查看后台运行的进程编号 3 ctrl+z 然程序进入后台并且暂停 3. fg %n 让后台运行的 ...