TextSwitcher

<span style="font-family:FangSong_GB2312;font-size:14px;"><span style="font-size:14px;">package cn.textswitcher.textswitcher;

import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import org.w3c.dom.Text;

import android.app.Activity;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.os.BaseBundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;


public class MainActivity extends Activity implements ViewFactory{
	private TextSwitcher mTxtContent2;
	private Rotate3dAnimation inAnimation;
	private Rotate3dAnimation outAnimation;
	final String mListLaunch[]=new String[]{"111111","222222","333333","444444","555555","666666"};
	
	Handler handler=new Handler(){

		private String newtext;

		public void handleMessage(Message msg) {
			int abc=msg.what;
			id = next1(); // 更新Id值
			
			updateText(); // 更新TextSwitcherd显示内容;
		}
	};
	int id = 0; //  数组的Id;
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mTxtContent2=(TextSwitcher) findViewById(R.id.txt_content2);
		mTxtContent2.setFactory(this);
		inAnimation = createAnim(-90, 0, true, true);
		outAnimation = createAnim(0, 90, false, true);
		mTxtContent2.setInAnimation(inAnimation);
		mTxtContent2.setOutAnimation(outAnimation);
		Timer timer=new Timer();
		timer.scheduleAtFixedRate(new MyTask(), 1, 3000);
	}
	

	class MyTask extends TimerTask{

		@Override
		public void run() {
			Message msg=Message.obtain();
			msg.what=1;
			handler.sendMessage(msg);
		}
	}

	@Override
	public View makeView() {
		TextView tv =new TextView(this);
        return tv;
	}
	
	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;
	}

	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 = mTxtContent2.getHeight() / 2;
			mCenterX = mTxtContent2.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);
		}
	}
	private int next1() {
		int flag = id + 1;
		if (flag > mListLaunch.length - 1) {
			flag = flag - mListLaunch.length;
		}
		return flag;
         
             
//        id=id+1;
//        if (id>mListLaunch.length-1) {
//            id=0;
//        }
//        return id;

      }

	
	private void updateText() {
		mTxtContent2.setText(mListLaunch[id]);
	}
}</span></span>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值