我試圖創建一個動畫,它將從左向右移動TextView
並無限循環。這是TextView
我想動畫:連續動畫從左到右的文字
<TextView
android:id="@+id/txtTitle"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="italic"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:ellipsize="end"
android:maxLines="1"
android:layout_centerHorizontal="true"
android:layout_below="@id/cardView" />
這我怎麼想動畫TextView
:
Animation animation = new TranslateAnimation(0, -280, 0, 0);
animation.setDuration(9000);
animation.setRepeatMode(Animation.RELATIVE_TO_SELF);
animation.setRepeatCount(Animation.INFINITE);
textView.setAnimation(animation);
我想實現的是對文本中的中心開出屏幕向右移動,一旦第一個字母離開屏幕,它應該重新出現在另一側。
正如一個側面說明所謂:你真的應該使用'Animator' API代替的視圖動畫。 「Animator」API是一個更新,更出色的動畫API,它得到了廣泛的支持(99%的設備)。作爲一個經驗法則:每個在其名稱中包含「Animation」的類(例如'TranslateAnimation')都是舊視圖動畫API的一部分,其名稱中包含'Animator'的所有內容都是更新的'Animator' API的一部分。 –