Amjad AL-Ahdal
Amjad AL-Ahdal

Reputation: 39

How to create a TextSwitcher with Animation

I wan to create a TextSwitcher with Animation Blink. When it fades the text should be changed. This is my Blink

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="2000"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
 </set>

My Fragment which contains the TextSwitcher

private TextSwitcher Test ;

    public HomeFragment() {
    // Required empty public constructor
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
        Test = (TextSwitcher)rootView.findViewById(R.id.TEST) ;

    Animation LeftSideAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.blink);

    Animation in = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);
    Animation out = AnimationUtils.loadAnimation(getActivity(),R.anim.blink);

    Test.setInAnimation(in);
    Test.setOutAnimation(out);



    return rootView;
}

My Fragment layout which has the part of the TextSwitcher I wrote it as the followings:

 <TextSwitcher
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/TEST">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello"
        android:textSize="20dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="YES"
        android:textSize="20dp"/>
</TextSwitcher>

Upvotes: 1

Views: 2703

Answers (1)

ElDuderino
ElDuderino

Reputation: 3263

Animation in = AnimationUtils.loadAnimation(this,android.R.anim.in);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.out);

switcher.setInAnimation(in);
switcher.setOutAnimation(out);

Upvotes: 4

Related Questions