Android基于ViewFilpper實現(xiàn)文字LED顯示效果示例
本文實例講述了Android基于ViewFilpper實現(xiàn)文字LED顯示效果。分享給大家供大家參考,具體如下:
這里給出來自Android官方API DEMO中動畫效果實例。
/**
* FlipperView文字效果動畫之:文字滾動動畫
*
* @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:// 文字從下進入,從上移出,伴隨透明度變化
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_up_in));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_up_out));
break;
case 1:// 文字從右側(cè)向左進入,從右側(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:// 多維空間動畫(復(fù)合動畫效果)
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>
動畫文件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"<!--動畫時長-->
android:fromYDelta="100%p"<!--Y方向初始位置-->
android:toYDelta="0" /><!--Y方向動畫結(jié)束位置-->
<alpha
android:duration="300"
android:fromAlpha="0.0"<!--初始透明度-->
android:toAlpha="1.0" /><!--動畫結(jié)束時透明度-->
</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è)置動畫插值器--> 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è)置啟動時間--> 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"<!--動畫結(jié)束畫面是否停留在最后一幀-->
android:fillEnabled="true"<!--使能填充效果-->
android:fromXScale="1.0"<!--X方向起始縮放值-->
android:fromYScale="1.0"<!--Y方向起始縮放值-->
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"<!--動畫相對于物件的X、Y坐標(biāo)的開始位置-->
android:pivotY="50%"
android:toXScale="1.4"
android:toYScale="0.6" />
<set android:interpolator="@android:anim/accelerate_interpolator" >
<scale<!--縮放動畫-->
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)動畫-->
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ā)動畫技巧匯總》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- 控制Android LED燈顏色的代碼實例
- 詳解Android應(yīng)用層制作LED指示燈
- Android實現(xiàn)文字和圖片混排(文字環(huán)繞圖片)效果
- android顯示TextView文字的倒影效果實現(xiàn)代碼
- Android實現(xiàn)文字翻轉(zhuǎn)動畫的效果
- Android實現(xiàn)文字滾動效果
- Android自定義Dialog實現(xiàn)文字動態(tài)加載效果
- Android中使用TextView實現(xiàn)文字跑馬燈效果
- Android編程實現(xiàn)文字倒影效果的方法
- Android Shader應(yīng)用開發(fā)之霓虹閃爍文字效果
- Android編程實現(xiàn)類似天氣預(yù)報圖文字幕垂直滾動效果的方法
相關(guān)文章
Android 開發(fā)使用PopupWindow實現(xiàn)彈出警告框的復(fù)用類示例
這篇文章主要介紹了Android 開發(fā)使用PopupWindow實現(xiàn)彈出警告框的復(fù)用類,結(jié)合實例形式分析了Android基于PopupWindow彈出警告框的復(fù)用類具體布局與功能實現(xiàn)技巧,需要的朋友可以參考下2020-05-05
Android開發(fā)之組件GridView簡單使用方法示例
這篇文章主要介紹了Android開發(fā)之組件GridView簡單使用方法,涉及Android GridView組件圖片瀏覽及保存圖片等相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
Flutter基于Dart Unwrapping Multiple Optional小技巧
這篇文章主要為大家介紹了Flutter Unwrapping Multiple Optional打開多個選項小技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
解決Android Studio 格式化快捷鍵和QQ 鎖鍵盤快捷鍵沖突問題
每次打開qq使用android studio格式化的快捷鍵Ctrl + Alt +L時,總是出現(xiàn)qq鎖鍵盤提示,怎么回事呢?下面小編給大家?guī)砹薬ndroid studio格式化的快捷鍵和qq快捷鍵之間的沖突的處理方法,需要的朋友參考下吧2017-12-12
Android Studio 通過登錄功能介紹SQLite數(shù)據(jù)庫的使用流程
SQLite是一款輕型的數(shù)據(jù)庫,是遵守ACID的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),它包含在一個相對小的C庫中。這篇文章主要介紹了Android Studio 通過登錄功能介紹SQLite數(shù)據(jù)庫的使用流程,需要的朋友可以參考下2018-09-09

