[Android] Textswitcher--What do you do?

Source: Internet
Author: User

Textswitcher 's Java Doc describes itself in this way:

Specialized Viewswitcher that contains only children of type TextView. A textswitcher is useful to animate a label on screen. Whenever SetText (charsequence) is called, Textswitcher animates the current text out and animates the new text in .

So, Textswitcher:
-There is a TextView child View
-When text is updated, the old text fades out and new text fades in, rendering the animated effect of smooth transitions

How to use Textswitcher step 1th: Add Textswitcher controls in Layout
    <TextSwitcher        android:id="@+id/ts"        android:layout_width="wrap_content"        android:layout_height="0dp"        android:layout_marginTop="20dp"        android:layout_weight="1" >    </TextSwitcher>
2nd step: Set up a factory for the Textswitcher control (for production views)
        mTs.setFactory(new TextSwitcher.ViewFactory() {            @Override            publicmakeView() {                final TextView tv = (TextView) LayoutInflater.from(                        null);                return tv;            }        });
3rd step: Setting the Fade animation
        mTs.setInAnimation(AnimationUtils.loadAnimation(                getApplicationContext(), android.R.anim.fade_in));        mTs.setOutAnimation(AnimationUtils.loadAnimation(                getApplicationContext(), android.R.anim.fade_out));

After that, the mTs.setText(txt) following effect is performed when the text is toggled:

Note: Full code on GITHUB

[Android] Textswitcher--What do you do?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.