TextSwitcher只能放两个textview控件。

主要属性设置:

android:inAnimation="@anim/setanimin"
android:outAnimation="@anim/setanimout"


XML代码如下:

<RelativeLayout 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/textSwitcher1"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:inAnimation="@anim/setanimin"
        android:outAnimation="@anim/setanimout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </TextSwitcher>
</RelativeLayout>


启动动画,java代码如下:

textSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher1);
action = new Runnable()
{
    @Override
    public void run()
    {
        num++;
        textSwitcher.setText(ss[ num % ss.length] );//通过setText启动动画
        textSwitcher.postDelayed(action , 1000);
    }
};
textSwitcher.postDelayed(action , 1000);



p_w_picpathSwitcher同理:

p_w_picpathSwitcher = (ImageSwitcher) findViewById(R.id.p_w_picpathSwitcher1);
        action = new Runnable()
        {
            @Override
            public void run()
            {
                num++;
                p_w_picpathSwitcher.setImageResource(mPhoto[num % 6]);
                p_w_picpathSwitcher.postDelayed(action , 5000);
            }
        };
        p_w_picpathSwitcher.postDelayed(action , 100);