Copper Street 1 -- TextSwitcher achieves text flop up and down effect,
TvNotice = (TextSwitcher) rootView. findViewById (R. id. TV _notice); tvNotice. setFactory (new ViewSwitcher. viewFactory () {// here is used to create an internal View. Here, TextView is created to display the text public View makeView () {TextView TV = new TextView (getContext ()); // set the text size TV. setTextSize (TypedValue. COMPLEX_UNIT_PX, getResources (). getDimension (R. dimen. group_notice_font_size); // sets the text color TV. setTextColor (getResources (). getColor (R. color. font_333333); return TV ;}});
Then you can use timer or Thread to control carousel. The code for controlling tvNotice in carousel is as follows:
// Set tvNotice. setInAnimation (AnimationUtils. loadAnimation (getContext (), R. anim. slide_in_bottom); // sets the cut-out animation tvNotice. setOutAnimation (AnimationUtils. loadAnimation (getContext (), R. anim. slide_out_up); // items is a string list, and index is the index tvNotice in the items to be displayed dynamically. setText (itmes. get (index ). getTitle ());
Slide_in_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top" > <translate android:duration="1000" android:fromYDelta="100%p" android:toYDelta="0" /> </set>
Slide_out_up.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top" > <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="-100%p" /> </set>