歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android實現界面組件的抖動效果

Android實現界面組件的抖動效果

日期:2017/3/1 10:16:55   编辑:Linux編程

Android實現界面組件的抖動效果采用的Animation動畫, 在系統提供的API Demos:

目錄為 \android-sdk\samples\android-8\ApiDemos 中已經實現了簡單的抖動效果 :

具體使用如下:

第一步:准備兩個動畫效果的XML文件,加入到 res/anim/目錄下:

Shake.xml文件:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="10"
android:duration="1000"
android:interpolator="@anim/cycle_7" />

cycle_7.xml文件:

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="7" />

第二步: //代碼使用動畫效果:

Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);//加載動畫資源文件
findViewById(R.id.xxxx).startAnimation(shake); //給組件播放動畫效果

Copyright © Linux教程網 All Rights Reserved