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);//滚动次数
  • 相关阅读:
    409. Longest Palindrome(计算一组字符集合可以组成的回文字符串的最大长度)
    242. Valid Anagram(两个字符串包含的字符是否完全相同)
    17. Letter Combinations of a Phone Number(电话号码的字母组合)
    模块XML真垃圾
    数据库是什么
    python项目开发规范
    面向对象之类的成员
    面向对象
    模块之 import os 模块一
    模块之序列化 import json
  • 原文地址:https://www.cnblogs.com/wangyuehome/p/3012329.html
Copyright © 2011-2022 走看看