Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果示例
本文實(shí)例講述了Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果。分享給大家供大家參考,具體如下:
這里給出來自Android官方API DEMO中動(dòng)畫效果實(shí)例。
/** * FlipperView文字效果動(dòng)畫之:文字滾動(dòng)動(dòng)畫 * * @description: * @author ldm * @date 2016-5-17 上午9:58:26 */ public class Animation2 extends Activity implements AdapterView.OnItemSelectedListener { // Spinner數(shù)據(jù)源 private String[] mStrings = { "Push up", "Push left", "Cross fade", "Hyperspace" }; // 控件ViewFlipper private ViewFlipper mFlipper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animation_2); // 初始化UI控件 initViews(); } private void initViews() { mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper)); mFlipper.startFlipping(); Spinner s = (Spinner) findViewById(R.id.spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mStrings); // 定義Spinner下拉菜單模式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 設(shè)置數(shù)據(jù) s.setAdapter(adapter); // 添加監(jiān)聽 s.setOnItemSelectedListener(this); } /** * Spinner的item選擇監(jiān)聽事件處理 */ @Override public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { switch (position) { case 0:// 文字從下進(jìn)入,從上移出,伴隨透明度變化 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out)); break; case 1:// 文字從右側(cè)向左進(jìn)入,從右側(cè)移出,伴隨透明度變化 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out)); break; case 2:// 文字透明度改變,從0-1-0 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); break; default:// 多維空間動(dòng)畫(復(fù)合動(dòng)畫效果) mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_out)); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub // DO NOTHING } }
布局文件,TextView中添加自己想顯示的文字
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dip" > <ViewFlipper android:id="@+id/flipper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dip" android:flipInterval="2000" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="@string/animation_2_text_1" android:textSize="26sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="@string/animation_2_text_2" android:textSize="26sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="@string/animation_2_text_3" android:textSize="26sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="@string/animation_2_text_4" android:textSize="26sp" /> </ViewFlipper> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:text="@string/animation_2_instructions" /> <Spinner android:id="@+id/spinner" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
動(dòng)畫文件res/anim文件夾下
1. push_up_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300"<!--動(dòng)畫時(shí)長(zhǎng)--> android:fromYDelta="100%p"<!--Y方向初始位置--> android:toYDelta="0" /><!--Y方向動(dòng)畫結(jié)束位置--> <alpha android:duration="300" android:fromAlpha="0.0"<!--初始透明度--> android:toAlpha="1.0" /><!--動(dòng)畫結(jié)束時(shí)透明度--> </set>
2. push_up_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromYDelta="0" android:toYDelta="-100%p" /> <alpha android:duration="300" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
3. push_left_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="100%p" android:toXDelta="0" /> <alpha android:duration="300" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
4. push_left_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="0" android:toXDelta="-100%p" /> <alpha android:duration="300" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
5. fade_in.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_longAnimTime" android:fromAlpha="0.0" android:interpolator="@interpolator/decelerate_quad" android:toAlpha="1.0" />
6. fade_out.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1.0" android:interpolator="@interpolator/accelerate_quad"<!--設(shè)置動(dòng)畫插值器--> android:toAlpha="0.0" />
7. hyperspace_in.xml
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromAlpha="0.0" android:startOffset="1200"<!--設(shè)置啟動(dòng)時(shí)間--> android:toAlpha="1.0" />
8. hyperspace_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <scale android:duration="700" android:fillAfter="false"<!--動(dòng)畫結(jié)束畫面是否停留在最后一幀--> android:fillEnabled="true"<!--使能填充效果--> android:fromXScale="1.0"<!--X方向起始縮放值--> android:fromYScale="1.0"<!--Y方向起始縮放值--> android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%"<!--動(dòng)畫相對(duì)于物件的X、Y坐標(biāo)的開始位置--> android:pivotY="50%" android:toXScale="1.4" android:toYScale="0.6" /> <set android:interpolator="@android:anim/accelerate_interpolator" > <scale<!--縮放動(dòng)畫--> android:duration="400" android:fillAfter="true" android:fillBefore="false" android:fillEnabled="true" android:fromXScale="1.4" android:fromYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:toXScale="0.0" android:toYScale="0.0" /> <rotate<!--旋轉(zhuǎn)動(dòng)畫--> android:duration="400" android:fillAfter="true" android:fillBefore="false" android:fillEnabled="true" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:toDegrees="-45" android:toYScale="0.0" /> </set> </set>
附開源代碼:https://github.com/ldm520/ANDROID_API_DEMOS
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)動(dòng)畫技巧匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- 控制Android LED燈顏色的代碼實(shí)例
- 詳解Android應(yīng)用層制作LED指示燈
- Android實(shí)現(xiàn)文字和圖片混排(文字環(huán)繞圖片)效果
- android顯示TextView文字的倒影效果實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)文字翻轉(zhuǎn)動(dòng)畫的效果
- Android實(shí)現(xiàn)文字滾動(dòng)效果
- Android自定義Dialog實(shí)現(xiàn)文字動(dòng)態(tài)加載效果
- Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果
- Android編程實(shí)現(xiàn)文字倒影效果的方法
- Android Shader應(yīng)用開發(fā)之霓虹閃爍文字效果
- Android編程實(shí)現(xiàn)類似天氣預(yù)報(bào)圖文字幕垂直滾動(dòng)效果的方法
相關(guān)文章
深入解讀Android的內(nèi)部進(jìn)程通信接口AIDL
這篇文章主要介紹了Android的內(nèi)部進(jìn)程通信接口AIDL,重點(diǎn)講解了進(jìn)程間的通信與AIDL內(nèi)存使用方面的parcelable接口的實(shí)現(xiàn),需要的朋友可以參考下2016-04-04Android 開發(fā)使用PopupWindow實(shí)現(xiàn)彈出警告框的復(fù)用類示例
這篇文章主要介紹了Android 開發(fā)使用PopupWindow實(shí)現(xiàn)彈出警告框的復(fù)用類,結(jié)合實(shí)例形式分析了Android基于PopupWindow彈出警告框的復(fù)用類具體布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-05-05Android開發(fā)之組件GridView簡(jiǎn)單使用方法示例
這篇文章主要介紹了Android開發(fā)之組件GridView簡(jiǎn)單使用方法,涉及Android GridView組件圖片瀏覽及保存圖片等相關(guān)操作技巧,需要的朋友可以參考下2019-03-03Flutter基于Dart Unwrapping Multiple Optional小技巧
這篇文章主要為大家介紹了Flutter Unwrapping Multiple Optional打開多個(gè)選項(xiàng)小技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12解決Android Studio 格式化快捷鍵和QQ 鎖鍵盤快捷鍵沖突問題
每次打開qq使用android studio格式化的快捷鍵Ctrl + Alt +L時(shí),總是出現(xiàn)qq鎖鍵盤提示,怎么回事呢?下面小編給大家?guī)砹薬ndroid studio格式化的快捷鍵和qq快捷鍵之間的沖突的處理方法,需要的朋友參考下吧2017-12-12Android Studio 通過登錄功能介紹SQLite數(shù)據(jù)庫(kù)的使用流程
SQLite是一款輕型的數(shù)據(jù)庫(kù),是遵守ACID的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),它包含在一個(gè)相對(duì)小的C庫(kù)中。這篇文章主要介紹了Android Studio 通過登錄功能介紹SQLite數(shù)據(jù)庫(kù)的使用流程,需要的朋友可以參考下2018-09-09android實(shí)現(xiàn)歌詞自動(dòng)滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)歌詞自動(dòng)滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11