Android 上下滾動TextSwitcher實例詳解
更新時間:2017年06月06日 17:25:29 投稿:lqh
這篇文章主要介紹了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://schemas.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://schemas.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.用線程或者定時器實現(xiàn)循環(huán)翻動。
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文本切換器和ViewFlipper使用詳解
- Android TextSwitcher實現(xiàn)文字上下翻牌效果(銅板街)
- Android App中用Handler實現(xiàn)ViewPager頁面的自動切換
- Android應用中圖片瀏覽時實現(xiàn)自動切換功能的方法詳解
- Android開發(fā)之使用ViewPager實現(xiàn)圖片左右滑動切換效果
- Android App仿微信界面切換時Tab圖標變色效果的制作方法
- Android自定義ImageView實現(xiàn)點擊兩張圖片切換效果
- Android實現(xiàn)圖片輪播切換實例代碼
- Android編程實現(xiàn)圖片背景漸變切換與圖層疊加效果
- Android實現(xiàn)加載狀態(tài)視圖切換效果
- Android開發(fā)實現(xiàn)自動切換文字TextSwitcher功能示例
相關文章
Android使用Intent.ACTION_SEND分享圖片和文字內容的示例代碼
這篇文章主要介紹了Android使用Intent.ACTION_SEND分享圖片和文字內容的示例代碼的實例代碼,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧2018-05-05Android實現(xiàn)動態(tài)向Gallery中添加圖片及倒影與3D效果示例
這篇文章主要介紹了Android實現(xiàn)動態(tài)向Gallery中添加圖片及倒影與3D效果的方法,涉及Android針對圖片的加載、顯示、翻轉、倒影等相關特效功能實現(xiàn)技巧2016-08-08