<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <com.example.marqueetextview.MarqueeText        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.marqueetextview.MarqueeText        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dp"        android:singleLine="true"        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:text="@string/hello_world" /></RelativeLayout>

后台实现:

public class MarqueeText extends TextView{    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 MarqueeText(Context context) {        super(context);        // TODO Auto-generated constructor stub    }        @Override    @ExportedProperty(category = "focus")    public boolean isFocused() {        //继承TextView类,重写isFocused方法,返回true,因为marquee只有在当前控件获取焦点时才会滚动。        return true;    }}

更多相关文章

  1. 三、安卓UI学习(1)
  2. android用户界面之按钮(Button)教程实例汇
  3. 在Fragment中设置控件点击方法,执行失败。
  4. TabHost与RadioGroup结合完成的菜单【带效果图】5个Activity
  5. Android常用控件
  6. android用户界面-组件Widget-画廊视图Gallery
  7. 总目录
  8. android 单元测试
  9. android 布局式跑马灯,非TextView

随机推荐

  1. Android之——自定义复合控件的实现
  2. android,不让edittext一进入页面就获取焦
  3. HwBinder原理总结-Android10.0 HwBinder
  4. Android Market有望后来居上
  5. android so库、jar包生成和使用
  6. Android Task概念以及相关
  7. Android ClassLoader详解
  8. Android中属性动画和补间动画的区别
  9. 源码分析Android AsyncTask
  10. Android 4.4 在启动到 ANDROID 闪光字的