关于TextView的跑马灯滚动方式
2015-12-22 09:45
447 查看
在layout里面添加TextView控件
- 自定义一个TextView
- 使用自定义的TextView
正常的TextView里面显示文字如果过长的话文字是折叠的,但是在如果项目需求是只能在一行里显示的话,滚动无疑还算是个不错的选择
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" //单行显示文字 android:singleLine="true" //以横向滚动方向显示(需要获取焦点) android:ellipsize="marquee" // 获取焦点 android:focusable="true" //获得焦点 android:focusableInTouchMode="true" />
这个时候其实已经实现了滚动的效果,但是真实的项目中往往要比这个复杂得多,所以我们放两个来试一下
- 自定义一个TextView
首先让这个类继承TextView,之后添加` public other(Context context) { super(context); // TODO Auto-generated constructor stub } public other(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub } public other(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override public boolean isFocused() { // TODO Auto-generated method stub return true; }`
- 使用自定义的TextView
还是之前的那个TextView我又复制了一个,把系统的TextView换成了自定义的TextView 引用自定义的TextView是全包名加类名
<com.example.texttest.other android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" /> <com.example.texttest.other android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" />
这样的话多行滚动就已经实现了,新人第一次写有不足的地方请多多指教,一边学习,一边把学习的成果发布出来
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories