Demo_文字翻转粗糙实现
2016-04-19 16:03
399 查看
AutoText.java
package com.example.kadh.test; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.TextSwitcher; import android.widget.TextView; public class AutoText extends TextSwitcher { String[] mStr = new String[]{"111111111111", "222222222222222222"}; private int mType = Animation.RELATIVE_TO_SELF; private TranslateAnimation mInDown; private TranslateAnimation mInUp; private TranslateAnimation mOutUp; private TranslateAnimation mOutDown; public AutoText(Context context) { super(context); } public AutoText(Context context, AttributeSet attrs) { super(context, attrs); init(context); } private void init(Context context) { for (int i = 0; i < mStr.length; i++) { TextView tv = new TextView(context); tv.setBackgroundResource(R.drawable.segment_normal_2_bg); tv.setGravity(View.TEXT_ALIGNMENT_CENTER); tv.setTextSize(26); tv.setText(mStr[i]); addView(tv); } mInUp = creatAnim(mType, 0,0 , 1, 0); mOutUp = creatAnim(mType, 0, 0, 0, -1); mInDown = creatAnim(mType, 0 , 0, -1 , 0); mOutDown = creatAnim(mType, 0, 0, 0, 1); setInAnimation(mInUp); setOutAnimation(mOutUp); } private TranslateAnimation creatAnim(int Type, float fromXValue, float toXValue, float fromYValue, float toYValue) { TranslateAnimation anim = new TranslateAnimation(Type, fromXValue, Type, toXValue, Type, fromYValue, Type, toYValue); anim.setDuration(1000); anim.setFillAfter(true); return anim; } public void upAnim() { setInAnimation(mInUp); setOutAnimation(mOutUp); } public void downAnim() { setInAnimation(mInDown); setOutAnimation(mOutDown); } }
MainActivity
package com.example.kadh.test; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { int count = 0; private AutoText mAouttext; private Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { if (count%2==1){ mAouttext.showNext(); mAouttext.downAnim(); }else { mAouttext.showPrevious(); mAouttext.upAnim(); } count++; mHandler.sendEmptyMessageDelayed(0, 1000); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAouttext = (AutoText) findViewById(R.id.aouttext); mHandler.sendEmptyMessageDelayed(0, 1000); }
相关文章推荐
- Http请求中Content-Type讲解以及在Spring MVC中的应用
- 过滤器、监听器、拦截器的区别
- “玲珑杯”郑州轻工业学院第八届ACM程序设计大赛暨河南高校邀请赛-正式赛
- Lua根据秒数返回时间串00:00:00
- 3D数学基础 - 坐标系、向量、矩阵
- Python学习(2)基本语法
- 元注解
- 283. Move Zeroes
- ASA不支持查看明细路由(某一IP)
- Android天气预报程序(六)
- Android M 动态权限获取
- android系统的 一些小工具类
- Oracle 表空间调整脚本
- android JS 互相调用
- chosen.jquery 插件 动态设置下拉选项被选中selected
- JQuery 对 Select option 的操作
- 你的应用是如何被替换的,App劫持病毒剖析
- 关于androidstudio创建新项目之后
- ios在真机调试中出现The executable was signed with invalid entitlements错误
- 读书笔记――javascript变量作用域