微信曾經(jīng)推出了一個(gè)查找附近好友的功能,大致功能是這樣的:屏幕上有一個(gè)按鈕,長(zhǎng)按按鈕的時(shí)候,會(huì)有一圈圈水波紋的動(dòng)畫向外擴(kuò)散,松手后,動(dòng)畫結(jié)束。
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、彌渡ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的彌渡網(wǎng)站制作公司
現(xiàn)在簡(jiǎn)單來(lái)實(shí)現(xiàn)這樣的一個(gè)動(dòng)畫功能:
思路: 主要用到了下面的藍(lán)色的圖片,定義三個(gè)ImageView,background都設(shè)置為藍(lán)色的圖片,然后定義一個(gè)包括縮放和透明度變化的動(dòng)畫集,然后每隔一段時(shí)間,讓3個(gè)ImageView依次啟動(dòng)這個(gè)動(dòng)畫集,看起來(lái)就像藍(lán)色的圓圈像水波紋向外擴(kuò)散一樣。

相關(guān)實(shí)現(xiàn)邏輯如下:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/wave1" android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" android:background="@drawable/wave" /> <ImageView android:id="@+id/wave2" android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" android:background="@drawable/wave"/> <ImageView android:id="@+id/wave3" android:layout_width="150dp" android:layout_height="150dp" android:layout_centerInParent="true" android:background="@drawable/wave" /> <ImageView android:id="@+id/normal" android:layout_width="166dp" android:layout_height="166dp" android:layout_centerInParent="true" android:background="@drawable/normal" /> </RelativeLayout>
MainActivity.java
package com.jackie.waveanimation;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView mNormal, mWave1, mWave2, mWave3;
private AnimationSet mAnimationSet1, mAnimationSet2, mAnimationSet3;
private static final int OFFSET = 600; //每個(gè)動(dòng)畫的播放時(shí)間間隔
private static final int MSG_WAVE2_ANIMATION = 2;
private static final int MSG_WAVE3_ANIMATION = 3;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_WAVE2_ANIMATION:
mWave2.startAnimation(mAnimationSet2);
break;
case MSG_WAVE3_ANIMATION:
mWave3.startAnimation(mAnimationSet3);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNormal = (ImageView) findViewById(R.id.normal);
mWave1 = (ImageView) findViewById(R.id.wave1);
mWave2 = (ImageView) findViewById(R.id.wave2);
mWave3 = (ImageView) findViewById(R.id.wave3);
mAnimationSet1 = initAnimationSet();
mAnimationSet2 = initAnimationSet();
mAnimationSet3 = initAnimationSet();
mNormal.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
showWaveAnimation();
break;
case MotionEvent.ACTION_UP:
clearWaveAnimation();
break;
case MotionEvent.ACTION_CANCEL:
clearWaveAnimation();
}
return true;
}
});
}
private AnimationSet initAnimationSet() {
AnimationSet as = new AnimationSet(true);
ScaleAnimation sa = new ScaleAnimation(1f, 2.3f, 1f, 2.3f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(OFFSET * 3);
sa.setRepeatCount(Animation.INFINITE);// 設(shè)置循環(huán)
AlphaAnimation aa = new AlphaAnimation(1, 0.1f);
aa.setDuration(OFFSET * 3);
aa.setRepeatCount(Animation.INFINITE);//設(shè)置循環(huán)
as.addAnimation(sa);
as.addAnimation(aa);
return as;
}
private void showWaveAnimation() {
mWave1.startAnimation(mAnimationSet1);
mHandler.sendEmptyMessageDelayed(MSG_WAVE2_ANIMATION, OFFSET);
mHandler.sendEmptyMessageDelayed(MSG_WAVE3_ANIMATION, OFFSET * 2);
}
private void clearWaveAnimation() {
mWave1.clearAnimation();
mWave2.clearAnimation();
mWave3.clearAnimation();
}
}
效果如下:


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
分享題目:Android實(shí)現(xiàn)水波紋外擴(kuò)效果的實(shí)例代碼
網(wǎng)頁(yè)路徑:http://www.chinadenli.net/article46/iehshg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、移動(dòng)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站收錄、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)