gpt4 book ai didi

android - 如何为 TextView (非常非常长的文本)设置动画水平自动滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:56 25 4
gpt4 key购买 nike

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

我是否遗漏了什么或者是否有更好的解决方法?

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>

代码 fragment 看起来像

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

最佳答案

我想你可以使用翻译动画。像这样

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromXDelta="100"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100" />

然后像这样添加到您的 TextView 中

textview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.scroll_animation));

希望对您有所帮助。

关于android - 如何为 TextView (非常非常长的文本)设置动画水平自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18826870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com