zoukankan      html  css  js  c++  java
  • android字幕滚动

    今天在一个listview里显示文本时,由于文本过长,导致填充了整条Item,很难看。可
    又不想把她截取成一小段,用“...”表示省略的。我想让文本都要显示出来,可以字幕
    滚动来实现。

    1,先在布局自定义一个TexView,设置好几个参数,单行、水平滚动。

    View Code
    <com.example.text.AlwaysMarqueeTextView
    android:id="@+id/text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:lines="1"
    android:scrollHorizontally="true"
    android:text="风儿飞飞鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅鹅
    
    鹅鹅鹅"
    android:textSize="20dp" />

    2.在com.example.text包下新建类AlwaysMarqueeTextView继承TextView,写几个构造
    方法和一个isFocused()方法。

    View Code
    package com.example.text;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    public class AlwaysMarqueeTextView extends TextView {
    
        public AlwaysMarqueeTextView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }
    
        public AlwaysMarqueeTextView(Context context, AttributeSet attrs) 
    
    {
            super(context, attrs);
        }
    
        public AlwaysMarqueeTextView(Context context, AttributeSet attrs,
                int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public boolean isFocused() {
            return true;
        }
    
    }

    3.获取要现实的空间TextView,设置三个参数,运行程序就OK了。

    View Code
    TextView tv2 = (TextView) findViewById(R.id.text2);
    tv2.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    tv2.setSingleLine(true);
    tv2.setMarqueeRepeatLimit(6);//滚动次数
  • 相关阅读:
    NHibernate中的Clear和Flush方法
    什么是POCO类
    node-vuecli 脚手架安装
    layui表单引入ueditor遇坑记
    PHP的九个超全局变量
    PHP的八个魔术常量
    PHP的七个数组指针函数
    TP6.0多应用模式隐藏路由中的应用名
    TP6.0中的密码验证逻辑、验证器的使用
    Vue 侦听器 watch
  • 原文地址:https://www.cnblogs.com/wangyuehome/p/3012329.html
Copyright © 2011-2022 走看看