Hackfive uses textswitcher and imageswitcher for smooth transition

Source: Internet
Author: User

1. application scenarios:

  • Browse the date list through the navigation buttons left and right
  • Change the date in the date selection space
  • Always countdown
  • New news
2. The knowledge points used are: textswitcher and imageswitcher textswitcher. To obtain the excessive Effect of user reservation, you only need to take the following simple steps:
  • Use the findviewbyid () method to obtain the result of the textswitcher object. Of course, you can also directly construct the object in the code.
  • Use the switcher. setfactory () method to specify the view-factory of textswitcher.
  • Use the switcher. setinanimation () method to set the animation effect.
  • Use the switcher. setoutanimation () method to set the animation effect.
Textswitcher first creates two views for switching in textswitcher through viewfactory. When the settext () method is called, textswitcher first removes the current view and displays setoutanimation () method setting animation, and then switch in another view, and display the animation set by the setinanimation () method.
  
 1 public class MainActivity extends Activity { 2     private static final String[] TEXTS = { "First", "Second", "Third" }; 3     private int mTextsPosition = 0; 4     private TextSwitcher mTextSwitcher; 5     @Override 6     public void onCreate(Bundle savedInstanceState) { 7         super.onCreate(savedInstanceState); 8         setContentView(R.layout.main); 9         mTextSwitcher = (TextSwitcher) findViewById(R.id.your_textview);10         mTextSwitcher.setFactory(new ViewFactory() {11             @Override12             public View makeView() {13                 System.out.println("makeView");14                 TextView t = new TextView(MainActivity.this);15                 t.setGravity(Gravity.CENTER);16                 return t;17             }18         });19         mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);20         mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);21         onSwitchText(null);22     }23     public void onSwitchText(View v) {24         mTextSwitcher.setText(TEXTS[mTextsPosition]);25         setNextPosition();26     }27     private void setNextPosition() {28         mTextsPosition = (mTextsPosition + 1) % TEXTS.length;29     }30 }  

Hackfive uses textswitcher and imageswitcher for smooth transition

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.