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