如何为文本视图设置动画(非常长的文本)自动水平滚动 [英] How to animate the textview (very very long text )scroll automatically horizontally

查看:27
本文介绍了如何为文本视图设置动画(非常长的文本)自动水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Marquee 不感兴趣,因为在 Marquee 中你无法控制 Marquee 的速度.我尝试为 textview 设置动画,但即使包含 textviews 的所有父布局和视图组都设置了两个标志 clipchildren=false、clipToPadding=false,父视图也会在末尾剪辑文本.

I am not interested in Marquee because, in Marquee you can not control the speed of marquee. I have tried to animate the textview but Parent view clips the text at the end even though all parent layout and view groups encompassing textviews are set with two flags clipchildren= false, clipToPadding=false.

我错过了什么还是有更好的解决方法?

Am I missing something or is there a better work around ?

xml看起来像

<TextView
        android:id="@+id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="66dp"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#585858"
        android:textSize="32sp" >
    </TextView>

代码片段看起来像

TextView textView2 = (TextView)findViewById( R.id.textview1 );    
textView2.startAnimation((Animation)AnimationUtils.loadAnimation(this, R.anim.translate));

推荐答案

我相信这肯定会解决大量观众的问题.

I am sure this will definitely solve the problem of the large audience out there.

Q: 自动水平滚动单行长文本消息(使用 hard_coding 或来自 string.xml)以合理的速度无限但使用选框(至少尝试一次).没有剪辑

Q: Auto-scroll a single line long text message(either using hard_coding or from string.xml) horizontally & infinitely at a reasonable speed but using marquee(try it once at least). No clipping

第 1 步:在activity_main.xml 文件中:

Step 1: In activity_main.xml file:

<TextView
    android:text="either hard coding or from string.xml"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"  
    android:background="@color/colorPrimary"
    android:textSize="18sp"
    android:marqueeRepeatLimit="marquee_forever"
    android:textColor="@android:color/background_light" />

第 2 步:在 main_activity java 文件中公共类 MainActivity 扩展 AppCompatActivity {

Step 2: In main_activity java file public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView textView = (TextView) findViewById(R.id.textView2);
    textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    textView.setSelected(true);
    textView.setSingleLine(true);
    textView.setText("Oxfam says 8 men as rich as half the world. | Govt may set threshold for probe into deposits. | At least 32 dead after Turkish plane hits village.");}}

//如果他已经输入了长输入,则可以删除最后一行

//one can remove the last line line if he has already feed the long input

这篇关于如何为文本视图设置动画(非常长的文本)自动水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆