textview动画无法正常工作

时间:2015-06-06 18:49:04

标签: android animation

我正在尝试从左到右滚动文本,但是当文本很长时,它会到达下一行而不是我想要的单个水平线。任何帮助都将不胜感激。我试图添加android:singleLine="true",但由于文本长度,它最终会删除一些文本。

动画:

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

   <translate
        android:fromXDelta="100%p"
        android:toXDelta="-100%p"
        android:duration="10000"
        android:repeatCount="infinite"
        android:repeatMode="restart" />
</set>

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#CC33FF" >

      <LinearLayout
          android:id="@+id/marquee"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#6e7071"
          android:orientation="horizontal" >

         <TextView
        android:id="@+id/text"
        android:text="@string/marquee" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textColor="#FFFFFF" />

        </LinearLayout>



</RelativeLayout>

主要活动:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);

        setContentView(R.layout.activity_main);

         TextView text = (TextView)findViewById( R.id.text );
            Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scroll_animation);
            text.startAnimation(animation);




    }
}

1 个答案:

答案 0 :(得分:0)

删除set tag并尝试这样

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