Android to achieve text scrolling effect, I wrote a timer small timer, TextView text up and down effect:
public class Autotextview extends Textswitcher implements Viewswitcher.viewfactory {private float mheight;
Private context Mcontext;
Minup,moutup respectively constitute a downward page of the animation private rotate3danimation minup;
Private Rotate3danimation Moutup;
Mindown,moutdown respectively constitute a downward page of the animation private rotate3danimation Mindown;
Private Rotate3danimation Moutdown;
Public Autotextview {This (context, NULL); TODO auto-generated Constructor stub} public Autotextview (context, AttributeSet attrs) {Super (context, a
TTRS);
TODO auto-generated constructor stub TypedArray a = Context.obtainstyledattributes (Attrs, r.styleable.auto3d);
Mheight = A.getdimension (r.styleable.auto3d_textsize, 16);
A.recycle ();
Mcontext = context;
Init ();
private void Init () {//TODO auto-generated Method stub setfactory (this);
Minup = Createanim ( -90, 0, True, true);
Moutup = Createanim (0, N, False, True);
Mindown = Createanim (0, True, false); Moutdown = CREAteanim (0, -90, false, false);
Textswitcher is mainly used for file switching, such as switching from text A to text B,//setinanimation (), a will perform inanimation,//setoutanimation (), and B will execute outanimation
Setinanimation (Minup);
Setoutanimation (Moutup); Private rotate3danimation Createanim (float start, float end, Boolean turnin, Boolean turnup) {final Rotate3danimati
On rotation = new Rotate3danimation (start, End, Turnin, turnup);
Rotation.setduration (800);
Rotation.setfillafter (FALSE);
Rotation.setinterpolator (New Accelerateinterpolator ());
return rotation; }//The TextView returned here is what we see View @Override public view Makeview () {//TODO auto-generated method stub TextView t = N
EW TextView (Mcontext);
T.setgravity (Gravity.center);
T.settextsize (16);
T.setmaxlines (1);
T.settextcolor (Mcontext.getresources (). GetColor (R.color.textcolor));
return t;
}//define action, scroll down page public void Previous () {if (Getinanimation ()!= mindown) {setinanimation (Mindown); } if (Getoutanimation ()!= moutdown) {setoutanimation (MOutdown);
}//define action, scroll up page public void next () {if (Getinanimation ()!= minup) {setinanimation (minup);
} if (Getoutanimation ()!= moutup) {setoutanimation (moutup);
} class Rotate3danimation extends Animation {private final float mfromdegrees;
Private final float mtodegrees;
private float Mcenterx;
private float mcentery;
Private Final Boolean mturnin;
Private Final Boolean mturnup;
Private Camera Mcamera; Public rotate3danimation (float fromdegrees, float todegrees, Boolean turnin, Boolean turnup) {mfromdegrees = Fromdegr
Ees
Mtodegrees = todegrees;
Mturnin = Turnin;
Mturnup = Turnup; @Override public void Initialize (int width, int height, int parentwidth, int parentheight) {super.initialize
(width, height, parentwidth, parentheight);
Mcamera = new Camera ();
Mcentery = GetHeight ()/2;
Mcenterx = GetWidth ()/2; @Override protected void applytransformation (float interpolatedtime, Transformation T) {final float fromdegrees = mfromdegrees;
Float degrees = fromdegrees + ((mtodegrees-fromdegrees) * interpolatedtime);
Final float CenterX = Mcenterx;
Final float centery = mcentery;
Final Camera Camera = Mcamera; Final int derection = Mturnup?
1:-1;
Final Matrix matrix = T.getmatrix ();
Camera.save ();
if (mturnin) {camera.translate (0.0f, derection *mcentery * (interpolatedtime-1.0f), 0.0f);
else {camera.translate (0.0f, derection *mcentery * (interpolatedtime), 0.0f);
} camera.rotatex (degrees);
Camera.getmatrix (matrix);
Camera.restore ();
Matrix.pretranslate (-centerx,-centery);
Matrix.posttranslate (CenterX, centery);
}
}
Demo Download Link: Http://xiazai.jb51.net/201611/yuanma/AndroidTextView (jb51.net). rar
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.