必须设置这2个,否则没效果!

android:singleLine="true"

android:focusableInTouchMode="true"


网上有的根本不能实现效果。莫非和版本有关?


另外:可参考http://www.eoeandroid.com/forum.php?mod=viewthread&tid=165922&reltid=183394&pre_thread_id=0&pre_pos=2&ext=

文本框内容文本的“跑马灯”效果在有些地方很有用。通过搜索学习,附件的源码把“跑马灯”的几种做法归纳在一起,供大家参考!!!!!!

下面是我的简单实现

XML定义:

默认的TextView

<TextView
android:id="@+id/marqueebyxml"
android:layout_width="5dip"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:focusableInTouchMode="true"
android:text="这是通过XML文件设置的效果!" />

自定义:

<com.wletv.MarqueeText
android:id="@+id/AMTV1"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginLeft="80dip"
android:textSize="25sp"
android:textColor="@android:color/black"
android:lines="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:background="#2FFFFFFF"
android:singleLine="true"
android:text="这才是真正的文字跑马灯效果,文字移动速度,文字移动方向,文字移动的样式,动画等等……"
/>


package com.wletv;


import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;


public class MarqueeText extends TextView {
public MarqueeText(Context con) {
super(con);
}


public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
}
}

更多相关文章

  1. 2011.07.05(3)——— android PopupWindow 以及activity切换的动
  2. 收集android上开源的酷炫的交互动画和视觉效果:Interactive-anima
  3. android textview 利用空格实现文字均匀分布
  4. android超炫button按钮动画效果
  5. android实现图片模糊背景效果
  6. Android 为图片添加文字水印
  7. Android MenuItem 设置文字颜色-TextColor的设置
  8. 自定义垂直文字view
  9. Android 系统自带Activity效果

随机推荐

  1. web前端开发是干嘛的?
  2. java线程池模型
  3. 最新版 IDEA激活码_idea激活码2021 免费
  4. 【2020最新】Python爬虫工程师 - 3个月成
  5. 必知必会! MySql 高频企业面试题
  6. 如何使用Illustrator裁剪图像、调整大小?
  7. 大数据基础系列之JAVA引用详解
  8. Spark部署模式另类详解
  9. Node.js仿知乎服务端-深入理解RESTful AP
  10. hadoop系列之MR经典案例分享二