大佬教程收集整理的这篇文章主要介绍了Android 上下滚动TextSwitcher实例详解,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Android 上下滚动TextSwitcher实例详解
1.在activity中需要代码声明
textSwitcher = (TextSwitcher)findViewById(R.id.text_switcher); textSwitcher.setFactory(new ViewFactory() { @Override public View makeView() { TextView tv = new TextView(MainActivity.this); tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP,16.0F); tv.setTextColor(Color.RED); return tv; } }); textSwitcher.seTinAnimation(AnimationUtils.loadAnimation(this,R.anim.anim_in)); textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.anim_out));
2.两个anim动画xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://scheR_678_11845@as.android.com/apk/res/android" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top"> <translate android:duration="3000" android:fromYDelta="100%p" android:toYDelta="0" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://scheR_678_11845@as.android.com/apk/res/android" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top"> <translate android:duration="3000" android:fromYDelta="0" android:toYDelta="-100%p" /> </set>
<style name="pop_anim"> <item name="android:windowEnterAnimation">@anim/anim_in</item> <item name="android:windowExitAnimation">@anim/anim_out</item> </style>
3.用线程或者定时器实现循环翻动。
Thread t = new Thread(new Runnable() { @Override public void run() { while (!flag) { message msg = new message(); msg.what = 1; msg.obj = getItem[i]; handler.sendmessage(msg); if (i== 2) { i = 0; } try { t.sleep(3000); i++; } catch (InterruptedException E) { // TODO Auto-generated catch block e.printStackTrace(); } } }
4.hanlder更新ui
private Handler handler = new Handler(){ public void handlemessage(android.os.message msg) { textSwitcher.setText((String)msg.obj); super.handlemessage(msg); }; };
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
以上是大佬教程为你收集整理的Android 上下滚动TextSwitcher实例详解全部内容,希望文章能够帮你解决Android 上下滚动TextSwitcher实例详解所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。