Android 上下滾動TextSwitcher實例詳解
更新時間:2017年06月06日 17:25:29 投稿:lqh
這篇文章主要介紹了Android 上下滾動TextSwitcher實例詳解的相關(guān)資料,需要的朋友可以參考下
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功能示例
相關(guān)文章
Android車載空調(diào)系統(tǒng)(HVAC)開發(fā)方法分析
HVAC?全稱:供暖通風與空氣調(diào)節(jié)(Heating?Ventilation?and?Air?Conditioning),用戶可以通過他來控制整個汽車的空調(diào)系統(tǒng),是汽車中非常重要的一個功能,汽車的空調(diào)HMI雖然并不復雜,但是大多都是用符號來表示功能,必須理解空調(diào)的各個符號表示的含義2023-12-12
Android自定義Seekbar滑動條 Pop提示跟隨滑動按鈕滑動
這篇文章主要為大家詳細介紹了Android自定義Seekbar滑動條,Pop提示跟隨滑動按鈕滑動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07
Android 中基于TabLayout+ViewPager實現(xiàn)標簽卡效果
這篇文章主要介紹了Android 中基于TabLayout+ViewPager實現(xiàn)標簽卡效果,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-12-12
Android MQTT與WebSocket協(xié)議詳細講解
MQTT(消息隊列遙測傳輸)是ISO 標準(ISO/IEC PRF 20922)下基于發(fā)布/訂閱范式的消息協(xié)議。它工作在TCP/IP協(xié)議族上,是為硬件性能低下的遠程設(shè)備以及網(wǎng)絡(luò)狀況糟糕的情況下而設(shè)計的發(fā)布/訂閱型消息協(xié)議2022-11-11
Android在不使用數(shù)據(jù)庫的情況下存儲數(shù)據(jù)的方法
這篇文章主要介紹了Android在不使用數(shù)據(jù)庫的情況下存儲數(shù)據(jù)的方法,涉及Android存儲數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2015-04-04

