Android 上下滾動(dòng)TextSwitcher實(shí)例詳解
Android 上下滾動(dòng)TextSwitcher實(shí)例詳解
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.兩個(gè)anim動(dòng)畫(huà)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.用線程或者定時(shí)器實(shí)現(xiàn)循環(huán)翻動(dòng)。
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); }; };
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android TextSwitcher文本切換器和ViewFlipper使用詳解
- Android TextSwitcher實(shí)現(xiàn)文字上下翻牌效果(銅板街)
- Android App中用Handler實(shí)現(xiàn)ViewPager頁(yè)面的自動(dòng)切換
- Android應(yīng)用中圖片瀏覽時(shí)實(shí)現(xiàn)自動(dòng)切換功能的方法詳解
- Android開(kāi)發(fā)之使用ViewPager實(shí)現(xiàn)圖片左右滑動(dòng)切換效果
- Android App仿微信界面切換時(shí)Tab圖標(biāo)變色效果的制作方法
- Android自定義ImageView實(shí)現(xiàn)點(diǎn)擊兩張圖片切換效果
- Android實(shí)現(xiàn)圖片輪播切換實(shí)例代碼
- Android編程實(shí)現(xiàn)圖片背景漸變切換與圖層疊加效果
- Android實(shí)現(xiàn)加載狀態(tài)視圖切換效果
- Android開(kāi)發(fā)實(shí)現(xiàn)自動(dòng)切換文字TextSwitcher功能示例
相關(guān)文章
Android使用Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Android使用Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10android上實(shí)現(xiàn)0.5px線條的原理分析
這篇文章主要介紹了android上實(shí)現(xiàn)0.5px線條的原理分析,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01Android實(shí)現(xiàn)注冊(cè)頁(yè)面
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)注冊(cè)頁(yè)面之監(jiān)聽(tīng)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04Android使用Intent.ACTION_SEND分享圖片和文字內(nèi)容的示例代碼
這篇文章主要介紹了Android使用Intent.ACTION_SEND分享圖片和文字內(nèi)容的示例代碼的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過(guò)來(lái)看看吧2018-05-05Android實(shí)現(xiàn)動(dòng)態(tài)向Gallery中添加圖片及倒影與3D效果示例
這篇文章主要介紹了Android實(shí)現(xiàn)動(dòng)態(tài)向Gallery中添加圖片及倒影與3D效果的方法,涉及Android針對(duì)圖片的加載、顯示、翻轉(zhuǎn)、倒影等相關(guān)特效功能實(shí)現(xiàn)技巧2016-08-08Android動(dòng)態(tài)顯示具體到秒的相聚時(shí)間
這篇文章主要為大家詳細(xì)介紹了Android動(dòng)態(tài)顯示具體到秒的相聚時(shí)間,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05