zoukankan      html  css  js  c++  java
  • TextView实现多个TextView对象的走马灯效果

    1:自定义一个控件继承TextView,重写isFocused方法,返回值为true;

    package com.example.helloandroid;
    
    import android.R.bool;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.ViewDebug.ExportedProperty;
    import android.widget.TextView;
    
    public class MarqueeText extends TextView {
    
        public MarqueeText(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
    
        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
        }
        @Override
        @ExportedProperty(category = "focus")
        public boolean isFocused() {
            // TODO Auto-generated method stub
            return true;
        }
    }

    2:给两个text空间添加属性,记得一定加上包名以及类名 

    <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.helloandroid.MarqueeText
            android:id="@+id/textView1"
            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.helloandroid.MarqueeText
            android:layout_below="@id/textView1"
            android:layout_margin="10dp"
            android:id="@+id/textView2"
            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" />
    </RelativeLayout>
  • 相关阅读:
    基于注解的springmvc开发
    判断两数之和
    redux-saga call 和 fork的区别
    滚动轴滚动方向判断
    原生方法scrollTo支持滚动特效
    npm下载包失败的几个原因
    关闭vscode打开新文件自动关闭预览文件功能
    在本地文件当中package.json的作用
    解决crlf 和 lf不同带来的冲突问题
    package-lock.json 文件的作用
  • 原文地址:https://www.cnblogs.com/rain-1/p/5145935.html
Copyright © 2011-2022 走看看