簡體   English   中英

android animation textview 從左到右旋轉字符串

[英]android animation textview rotate string left to right

我需要把textview里面的String從左到右動畫化,這樣當從右邊去掉文字時,就可以從左邊輸入了,如下圖。

初始 state

上面的文字(Compute Sentence Probability)必須按如下動畫,從圖像中移除並在另一側輸入,如下圖所示。

動畫 state

我使用了下面的animation,但是在這個animation中,整個文本從右到左一次,再次它不會在文本離開另一側的同時輸入,直到整個文本才再次輸入文字出來了。

animation

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
  android:duration="6000"
  android:fromXDelta="100%"
  android:interpolator="@android:anim/linear_interpolator"
  android:repeatCount="infinite"
  android:repeatMode="restart"
  android:toXDelta="-100%" />

TextView

在您的 xml 文件中添加 textview

<TextView
    android:id="@+id/tvUsername"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Computer Sentence Probability..........."
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
 />

在 java 文件中簡單添加這一行

TextView tvUsername = (TextView)findViewById(R.id.tvUsername);  
tvUsername.setSelected(true);

此答案有效,如果您想從右到左支持可以將以下代碼添加到 xml 中的 TextView

android:textDirection="rtl"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM