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>
  • 相关阅读:
    【2018.10.3】万圣节的快递
    【2018.10.3】万圣节的入场券
    【2018.10.2】纸条
    【2018.10.2】菌落合并
    【2018.10.2】Note of CXM
    【2018.10.1】【JSOI2016】最佳团体(bzoj4753)
    【2018.10.1】「JOI 2014 Final」年轮蛋糕
    【2018.9.26】K-D Tree详解
    Python中的numpy模块解析
    Python中xlrd模块解析
  • 原文地址:https://www.cnblogs.com/rain-1/p/5145935.html
Copyright © 2011-2022 走看看