亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果示例

 更新時(shí)間:2017年08月18日 12:32:14   作者:遲做總比不做強(qiáng)  
這篇文章主要介紹了Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果,結(jié)合完整實(shí)例形式分析了Android使用ViewFilpper實(shí)現(xiàn)文字LED顯示動(dòng)畫(huà)效果的相關(guān)步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android基于ViewFilpper實(shí)現(xiàn)文字LED顯示效果。分享給大家供大家參考,具體如下:

這里給出來(lái)自Android官方API DEMO中動(dòng)畫(huà)效果實(shí)例。

/**
 * FlipperView文字效果動(dòng)畫(huà)之:文字滾動(dòng)動(dòng)畫(huà)
 *
 * @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)聽(tīng)
    s.setOnItemSelectedListener(this);
  }
  /**
   * Spinner的item選擇監(jiān)聽(tīng)事件處理
   */
  @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)畫(huà)(復(fù)合動(dòng)畫(huà)效果)
      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)畫(huà)文件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)畫(huà)時(shí)長(zhǎng)-->
    android:fromYDelta="100%p"<!--Y方向初始位置-->
    android:toYDelta="0" /><!--Y方向動(dòng)畫(huà)結(jié)束位置-->
  <alpha
    android:duration="300"
    android:fromAlpha="0.0"<!--初始透明度-->
    android:toAlpha="1.0" /><!--動(dòng)畫(huà)結(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)畫(huà)插值器-->
  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)畫(huà)結(jié)束畫(huà)面是否停留在最后一幀-->
    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)畫(huà)相對(duì)于物件的X、Y坐標(biāo)的開(kāi)始位置-->
    android:pivotY="50%"
    android:toXScale="1.4"
    android:toYScale="0.6" />
  <set android:interpolator="@android:anim/accelerate_interpolator" >
    <scale<!--縮放動(dòng)畫(huà)-->
      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)畫(huà)-->
      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>

附開(kāi)源代碼:https://github.com/ldm520/ANDROID_API_DEMOS

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)動(dòng)畫(huà)技巧匯總》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論