Android 带渐变的文本切换器

Android 带渐变的文本切换器,android,Android,我使用R.anim.fade_输入和输出设置了一个文本切换器。当我点击按钮我看到文本,下一次点击我看不到文本可见(如淡出),下一次点击文本是确定的,再次下一次,测试是不可见的。我的错误在哪里 mSwitcher = (TextSwitcher) findViewById(R.id.switcher); mSwitcher.setFactory(this); Animation in = AnimationUtils.loadAnimation(this,android.

我使用R.anim.fade_输入和输出设置了一个文本切换器。当我点击按钮我看到文本,下一次点击我看不到文本可见(如淡出),下一次点击文本是确定的,再次下一次,测试是不可见的。我的错误在哪里

mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
      mSwitcher.setFactory(this);

      Animation in = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);
      Animation out = AnimationUtils.loadAnimation(this,android.R.anim.fade_out);
      mSwitcher.setInAnimation(in);
      mSwitcher.setOutAnimation(out);

mSwitcher.setText(""+prog[x]);

下面是一个简单的例子,它使用
fix
实现ViewFactory和安全递增计数器,以从字符串数组中获取适当的元素

主要内容:

和xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextSwitcher
        android:id="@+id/textswitcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="next" />

</LinearLayout>


如果希望调用元素的元素数组超出范围,则显示将无法正常工作。。。请注意。

数组:prog[0]=“1”,prog[1]=“2”如果x索引超出范围,会发生什么?空指针异常。为什么?应用程序运行,但我有一个类似于上面的问题。因为文档中说用户在每次调用setText()时都会看到动画,请遵循下面的示例,我完成了我的应用程序
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextSwitcher
        android:id="@+id/textswitcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="next" />

</LinearLayout>