This article is intended to talk about the use of Textviewswitcher and Imageviewswitcher.
Simple TextView and ImageView when changing content, the switch between the new content and the old content looks very stiff.
The corresponding extension classes, Textviewswitcher, and Imageviewswitcher are available in the Android SDK to animate the switching content.
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Fill_ Parent " android:layout_height=" fill_parent "> <textswitcher android:id=" @+id/your_textview " android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_ Centerinparent= "true"/> <button android:layout_width= "fill_parent" android:layout_height= " Wrap_content " android:layout_alignparentbottom=" true " android:onclick=" Onswitchtext " android: text= "Click to replace Text"/></relativelayout>
public class Mainactivity extends Activity {private static final string[] texts = {"hello! "How is U?" "," Fine,and u? " }; private int mtextsposition = 0; Private Textswitcher Mtextswitcher; @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.main); Gets an instance of textswitcher Mtextswitcher = (textswitcher) Findviewbyid (R.id.your_textview); Mtextswitcher.setfactory (New Viewfactory () {@Override public View Makeview () {TEXTV Iew t = new TextView (mainactivity.this); T.setgravity (Gravity.center); return t; } }); Set new content into the animated mtextswitcher.setinanimation (this, Android. R.ANIM.FADE_IN); Sets the move-out animation for old content mtextswitcher.setoutanimation (this, Android. R.anim.fade_out); Buton Click event ONSWITCHText (NULL); } public void Onswitchtext (View v) {mtextswitcher.settext (texts[mtextsposition]); Setnextposition (); } private void Setnextposition () {mtextsposition = (mtextsposition + 1)% Texts.length; }}
The imageviewswitcher is used in a very similar way to Textviewswitcher.
"Android Development Tips" magical textviewswitcher and Imageviewswitcher