在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢?

---------------------------------------------------------------------

以下列出解决方法:

1. 新建TextView控件

<TextView

android:id="@+id/textView"

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/demo"/>

2. 重写TextView控件的样式(新建MarqueeText.java)

public class MarqueeText extends TextView {

public MarqueeText(Context context) {

super(context);

}

public MarqueeText(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

public MarqueeText(Context context, AttributeSet attrs) {

super(context, attrs);

}

@Override

public boolean isFocused() {

return true; //默认为false,设置为true为了让每个TextView都获取焦点

}

}

3. 将<TextView />更改为<com.demo.marqueetextview.MarqueeText.java[s1]

------à>>>这样的话就实现了对TextView的重写

===================================================

以上方法即实现了仿跑马灯效果的TextView

2015-01-31


[s1]这个地方为重写的java文件所在的包(精确到java文件~)

Android成长日记-仿跑马灯的TextView的更多相关文章

  1. Android 开发笔记___textvieww__跑马灯效果

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  2. Android使用Canvas实现跑马灯

    网上的很多的教程都是通过更改TextView的属性进行跑马灯的设计.这样做有很多的缺点: 1.如果TextView没有获取焦点,那么跑马灯的效果无法实现. 2.如果文本长度小于TextView的宽度, ...

  3. Android成长日记-使用GridView显示多行数据

    本节将实现以下效果 Ps:看起来很不错的样子吧,而且很像九宫格/se ----------------------------------------------------------------- ...

  4. Android成长日记-Fragment

    (一)Android在3.0中引入了Fragment的概念,主要目的是用在大屏幕设备上—例如平板电脑上,支持更加动态和灵活的UI设计.平板电脑的屏幕要比手机大的多,有更多的空间放更多的UI组件,并且这 ...

  5. Android 用ViewFlipper实现跑马灯效果的公告提示

    1.代码部分private void initViewFlipper(final HomepageListModel.Notice notice) { for (int i = 0; i < n ...

  6. Android成长日记-Android四大组件之Service组件的学习

    1.什么是Service? Service是Android四大组件中与Activity最相似的组件,它们都代表可执行的程序,Service与Activity的区别在于:Service一直在后台运行,它 ...

  7. Android成长日记-数据存储之SQLite[1]

    [SQLite简介] SQLite是R.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准,并且可以在所有主要的操作系统上运行 ---支持高达2TB大小的数据库: ...

  8. Android成长日记-五大布局

    1. 五布局之线性布局LinearLayout 特点:它包含的子控件将以横向或竖向的方式排列 ps:android:gravity=”center|bottom”(gravity允许多级联用) Tip ...

  9. Android成长日记-数据存储之SharedPreferences

    数据篇-SharedPreferences Android的四种存储方式 1. SharedPreferences 2. SQLite 3. Content Provider 4. File ---- ...

随机推荐

  1. vue 滚动加载

    <template> <div class="wraper" @scroll="onScroll($event)"> <div c ...

  2. mongodb.conf配置文件详解

    mongod --config /etc/mongodb.conf 配置如下:verbose:日志信息冗余.默认false.提高内部报告标准输出或记录到logpath配置的日志文件中.要启用verbo ...

  3. 扩展 easyui-tabs 插件 关闭标签页方法

    $.extend($.fn.tabs.methods,{ allTabs:function(jq){ var tabs = $(jq).tabs('tabs'); var all = []; all ...

  4. Logging的这点小事

    真正做项目,才发觉Logging的好处和学问.自己胡搞的时候,常常使用System.out.println作为输出. 但实际的项目,尤其是library比较多的时候,好好配置好Logging,才能在后 ...

  5. node 学习笔记 - Modules 模块加载系统 (1)

    本文同步自我的个人博客:http://www.52cik.com/2015/12/11/learn-node-modules-path.html 用了这么久的 require,但却没有系统的学习过 n ...

  6. PHP 页面跳转方法

    1.php header()函数跳转 PHP的header()函数非常强大,其中在页面url跳转方面也调用简单,使用header()直接跳转到指定url页面,这时页面跳转是302重定向: $url = ...

  7. STL中的next_permutation

    给定一个数组a[N],求下一个数组. 2 1 3 4 2 1 4 3 2 3 1 4 2 3 4 1 ..... 在STL中就有这个函数: 1.参数是(数组的第一个元素,数组的末尾),注意这是前闭后开 ...

  8. 十天冲刺---Day9

    站立式会议 站立式会议内容总结: 燃尽图 照片 队员们都回来了,写完之后继续对alpha版本进行迭代. 希望演示的时候能拿得出来.

  9. android开机自启动广播

    权限<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>     &l ...

  10. 数组的方法 Array.map();Array.every()和Array.some();数组的indexof();检测是否是数组isArray(obj);

    数组的方法 Array.map(); 栗子: var a=[1,2,,3]; var b=a.map( function(value){return value*value} ); alert(b); ...