• android marquee textview 走马灯效果


    网上查的全都不能用。还是自己试验出来的。。。

    测试机版本:4.0.3

    网上有文章说要加 addStatesFromChildren

    实测:加不加都能正常滚动

    android:focusable="true"

    实测:必须在xml里添加。在程序中使用tv.setFocusable(true);不能滚动

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:addStatesFromChildren="true"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="11adshfkalhafklajfhkadjfhakjfhdjkfhadfjkhasdfhasdfjkhashkadjfhakjfhdjkfhadfjkhasdfhasdfjkhashkadjfhakjfhdjkfhadfjkhasdfhasdfjkhashkadjfhakjfhdjkfhadfjkhasdfhasdfjkhashkadjfhakjfhdjkfhadfjkhasdfhasdfjkhasdjkfhsdakfhasdjkfhasdkfhsajkdfhsdfhsadfkjhsaf" />
    
        <Button
            android:id="@+id/xinle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="sad" />
    
    </LinearLayout>

     点击button可以切换模式

    findViewById(R.id.xinle).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    flag = !flag;
                    if (flag) {
                        textView.setEllipsize(TextUtils.TruncateAt.valueOf("END"));
                        return;
                    }
                    textView.setEllipsize(TextUtils.TruncateAt.valueOf("MARQUEE"));
                }
            });

    关于ellipsize这个参数的用法

    在xml中

    android:ellipsize = "end"    省略号在结尾

    android:ellipsize = "start"   省略号在开头

    android:ellipsize = "middle"     省略号在中间

    android:ellipsize = "marquee"  跑马灯

    最好加一个约束android:singleline = "true"

    当然也可以用代码语句

    tv.setEllipsize(TextUtils.TruncateAt.valueOf("END"));

    tv.setEllipsize(TextUtils.TruncateAt.valueOf("START"));

    tv.setEllipsize(TextUtils.TruncateAt.valueOf("MIDDLE"));

    tv.setEllipsize(TextUtils.TruncateAt.valueOf("MARQUEE"));

    最好再加一个约束tv.setSingleLine(true);

  • 相关阅读:
    C++编写ATM(2)
    【Python排序搜索基本算法】之Dijkstra算法
    Java中List转换为数组,数组转List
    [置顶] 亚信联创实习笔记
    PL/SQL 异常处理程序
    CSS position财产
    malloc()与calloc差异
    Qt5官方demo分析集10——Qt Quick Particles Examples
    栈和堆之间的差
    深入浅出JMS(一)——JMS简要
  • 原文地址:https://www.cnblogs.com/622698abc/p/3833550.html
Copyright © 2020-2023  润新知