国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現文字滾動效果

2019-12-12 04:28:26
字體:
來源:轉載
供稿:網友

Android 實現文字滾動效果,自己寫了個timer小計時器,textview文字上下翻動效果:

public class AutoTextView extends TextSwitcher implements  ViewSwitcher.ViewFactory { private float mHeight; private Context mContext; //mInUp,mOutUp分別構成向下翻頁的進出動畫 private Rotate3dAnimation mInUp; private Rotate3dAnimation mOutUp;  //mInDown,mOutDown分別構成向下翻頁的進出動畫 private Rotate3dAnimation mInDown; private Rotate3dAnimation mOutDown;  public AutoTextView(Context context) {  this(context, null);  // TODO Auto-generated constructor stub } public AutoTextView(Context context, AttributeSet attrs) {  super(context, attrs);  // 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, 90, false, true);  mInDown = createAnim(90, 0 , true , false);  mOutDown = createAnim(0, -90, false, false);  //TextSwitcher主要用于文件切換,比如 從文字A 切換到 文字 B,  //setInAnimation()后,A將執行inAnimation,  //setOutAnimation()后,B將執行OutAnimation  setInAnimation(mInUp);  setOutAnimation(mOutUp); }  private Rotate3dAnimation createAnim(float start, float end, boolean turnIn, boolean turnUp){  final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, turnIn, turnUp);  rotation.setDuration(800);  rotation.setFillAfter(false);  rotation.setInterpolator(new AccelerateInterpolator());  return rotation; } //這里返回的TextView,就是我們看到的View @Override public View makeView() {  // TODO Auto-generated method stub  TextView t = new TextView(mContext);  t.setGravity(Gravity.CENTER);  t.setTextSize(16);  t.setMaxLines(1);  t.setTextColor(mContext.getResources().getColor(R.color.textColor));  return t; } //定義動作,向下滾動翻頁 public void previous(){  if(getInAnimation() != mInDown){   setInAnimation(mInDown);  }  if(getOutAnimation() != mOutDown){   setOutAnimation(mOutDown);  } } //定義動作,向上滾動翻頁 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 = fromDegrees;    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下載鏈接:http://xiazai.VeVB.COm/201611/yuanma/AndroidTextView(VeVB.COm).rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 紫阳县| 沿河| 波密县| 运城市| 河西区| 宁安市| 乌拉特中旗| 张家口市| 勐海县| 西乌珠穆沁旗| 宁城县| 崇左市| 宣威市| 大新县| 肇州县| 怀柔区| 板桥市| 大姚县| 仙桃市| 张北县| 桃江县| 南皮县| 吴旗县| 吉安县| 嵊州市| 罗甸县| 扎赉特旗| 合山市| 双流县| 娄底市| 灵璧县| 湄潭县| 灌阳县| 莱西市| 辽宁省| 涪陵区| 武山县| 禹州市| 驻马店市| 平塘县| 商水县|