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

Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼

 更新時(shí)間:2018年05月16日 14:14:53   作者:LiuJun2Son  
這篇文章主要介紹了Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

本文講述了Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼。分享給大家供大家參考,具體如下:

項(xiàng)目地址下載

1.效果圖:

2.使用方法:

在xml里使用RippleImageView自定義控件:

xmlns:app="http://schemas.android.com/apk/res-auto"
<com.army.rippleimage.RippleImageView
 android:id="@+id/rippleImageView"
 android:layout_width="match_parent"
 android:layout_height="180dp"
 android:background="#37B158"
 app:show_spacing_time="800"http://動(dòng)畫(huà)播放間隔時(shí)間
 app:imageViewWidth="35dp"http://圖片的大小
 app:imageViewHeigth="35dp"
 android:layout_centerHorizontal="true">
</com.army.rippleimage.RippleImageView>

在Activity中的使用:

rippleImageView=(RippleImageView)findViewById(R.id.rippleImageView);
//開(kāi)始動(dòng)畫(huà)
rippleImageView.startWaveAnimation();
//停止動(dòng)畫(huà)
rippleImageView.stopWaveAnimation();

3.如何將自定義控件引入到項(xiàng)目:

拷貝自定義控件RippleImageView

/**
 * Description :
 * Author : liujun
 * Email : liujin2son@163.com
 */
public class RippleImageView extends RelativeLayout {
 private static final int SHOW_SPACING_TIME=700;
 private static final int MSG_WAVE2_ANIMATION = 1;
 private static final int MSG_WAVE3_ANIMATION = 2;
 private static final int IMAMGEVIEW_SIZE = 80;
 /**三張波紋圖片*/
 private static final int SIZE =3 ;
 /**動(dòng)畫(huà)默認(rèn)循環(huán)播放時(shí)間*/
 private int show_spacing_time=SHOW_SPACING_TIME;
 /**初始化動(dòng)畫(huà)集*/
 private AnimationSet [] mAnimationSet=new AnimationSet[SIZE];
 /**水波紋圖片*/
 private ImageView [] imgs=new ImageView[SIZE];
 /**背景圖片*/
 private ImageView img_bg;
 /**水波紋和背景圖片的大小*/
 private float imageViewWidth=IMAMGEVIEW_SIZE;
 private float imageViewHeigth=IMAMGEVIEW_SIZE;
 private Handler mHandler = new Handler() {
 @Override
 public void handleMessage(Message msg) {
 switch (msg.what) {
 case MSG_WAVE2_ANIMATION:
  imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE2_ANIMATION]);
  break;
 case MSG_WAVE3_ANIMATION:
  imgs[MSG_WAVE2_ANIMATION].startAnimation(mAnimationSet[MSG_WAVE3_ANIMATION]);
  break;
 }
 }
 };
 public RippleImageView(Context context) {
 super(context);
 initView(context);
 }
 public RippleImageView(Context context, AttributeSet attrs) {
 super(context, attrs);
 getAttributeSet(context,attrs);
 initView(context);
 }
 /**
 * 獲取xml屬性
 * @param context
 * @param attrs
 */
 private void getAttributeSet(Context context, AttributeSet attrs) {
 TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.custume_ripple_imageview);
 show_spacing_time = typedArray.getInt(R.styleable.custume_ripple_imageview_show_spacing_time, SHOW_SPACING_TIME);
 imageViewWidth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewWidth, IMAMGEVIEW_SIZE);
 imageViewHeigth = typedArray.getDimension(R.styleable.custume_ripple_imageview_imageViewHeigth, IMAMGEVIEW_SIZE);
 Log.d("TAG","show_spacing_time="+show_spacing_time+"mm imageViewWidth="+imageViewWidth+"px imageViewHeigth="+imageViewHeigth+"px");
 typedArray.recycle();
 }
 private void initView(Context context) {
 setLayout(context);
 for (int i = 0; i <imgs.length ; i++) {
 mAnimationSet[i]=initAnimationSet();
 }
 }
 /**
 * 開(kāi)始動(dòng)態(tài)布局
 */
 private void setLayout(Context context) {
 LayoutParams params=new LayoutParams(dip2px(context,imageViewWidth),dip2px(context,imageViewHeigth));
 //添加一個(gè)規(guī)則
 params.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
 /**添加水波紋圖片*/
 for (int i = 0; i <SIZE ; i++) {
 imgs[i] = new ImageView(context);
 imgs[i].setImageResource(R.mipmap.point_empty);
 addView(imgs[i],params);
 }
 LayoutParams params_bg=new LayoutParams(dip2px(context,imageViewWidth)+10,dip2px(context,imageViewHeigth)+10);
 //添加一個(gè)規(guī)則
 params_bg.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
 /**添加背景圖片*/
 img_bg=new ImageView(context);
 img_bg.setImageResource(R.mipmap.point_org);
 addView(img_bg,params_bg);
 }
 /**
 * 初始化動(dòng)畫(huà)集
 * @return
 */
 private AnimationSet initAnimationSet() {
 AnimationSet as = new AnimationSet(true);
 //縮放度:變大兩倍
 ScaleAnimation sa = new ScaleAnimation(1f, 2f, 1f, 2f,
 ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
 ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
 sa.setDuration(show_spacing_time * 3);
 sa.setRepeatCount(Animation.INFINITE);// 設(shè)置循環(huán)
 //透明度
 AlphaAnimation aa = new AlphaAnimation(1, 0.1f);
 aa.setDuration(show_spacing_time * 3);
 aa.setRepeatCount(Animation.INFINITE);//設(shè)置循環(huán)
 as.addAnimation(sa);
 as.addAnimation(aa);
 return as;
 }
 private static int dip2px(Context context, float dipValue) {
 final float scale = context.getResources().getDisplayMetrics().density;
 return (int) (dipValue * scale + 0.5f);
 }
 //============================對(duì)外暴露的public方法=========================================
 /**
 * 開(kāi)始水波紋動(dòng)畫(huà)
 */
 public void startWaveAnimation() {
 imgs[0].startAnimation(mAnimationSet[0]);
 mHandler.sendEmptyMessageDelayed(MSG_WAVE2_ANIMATION, show_spacing_time);
 mHandler.sendEmptyMessageDelayed(MSG_WAVE3_ANIMATION, show_spacing_time * 2);
 }
 /**
 * 停止水波紋動(dòng)畫(huà)
 */
 public void stopWaveAnimation() {
 for (int i = 0; i <imgs.length ; i++) {
 imgs[i].clearAnimation();
 }
 }
 /**獲取播放的速度*/
 public int getShow_spacing_time() {
 return show_spacing_time;
 }
 /**設(shè)計(jì)播放的速度,默認(rèn)是800毫秒*/
 public void setShow_spacing_time(int show_spacing_time) {
 this.show_spacing_time = show_spacing_time;
 }
}

拷貝自定義屬性到arrts下

<declare-styleable name="custume_ripple_imageview">
 <attr name="show_spacing_time" format="integer"></attr>
 <attr name="imageViewWidth" format="dimension"></attr>
 <attr name="imageViewHeigth" format="dimension"></attr>
</declare-styleable>

拷貝默認(rèn)圖片

相關(guān)文章

  • 詳解Android UI更新的幾種方法

    詳解Android UI更新的幾種方法

    本篇文章主要介紹了Android UI更新的幾種方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06
  • Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果逐步完成過(guò)程

    Android自定義View實(shí)現(xiàn)圓弧進(jìn)度效果逐步完成過(guò)程

    在Android開(kāi)發(fā)中,通過(guò)自定義View實(shí)現(xiàn)自己想要的效果是作為android開(kāi)發(fā)程序員的一項(xiàng)必備技能,自定義View對(duì)于android開(kāi)發(fā)來(lái)說(shuō)也是比較難的一項(xiàng)技術(shù)
    2023-04-04
  • Android如何自定義升級(jí)對(duì)話框示例詳解

    Android如何自定義升級(jí)對(duì)話框示例詳解

    對(duì)話框是我們?cè)谄綍r(shí)經(jīng)常會(huì)遇到的一個(gè)功能,但自帶的對(duì)話框不夠美觀,大家一般都會(huì)自定義,下面這篇文章主要給大家介紹了關(guān)于Android如何自定義升級(jí)對(duì)話框的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-08-08
  • Android Doze模式啟用和恢復(fù)詳解

    Android Doze模式啟用和恢復(fù)詳解

    這篇文章主要介紹了Android Doze模式啟用和恢復(fù)功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • Flutter中抽屜組件Drawer使用詳解

    Flutter中抽屜組件Drawer使用詳解

    這篇文章主要為大家詳細(xì)介紹了Flutter中抽屜組件Drawer使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能實(shí)例

    Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能實(shí)例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)簡(jiǎn)單流量管理功能的方法,結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)流量監(jiān)控所涉及的功能模塊與布局技巧,需要的朋友可以參考下
    2016-02-02
  • android?sharedUserId?使用知識(shí)盲點(diǎn)解析

    android?sharedUserId?使用知識(shí)盲點(diǎn)解析

    這篇文章主要為大家介紹了android?sharedUserId使用的知識(shí)盲點(diǎn)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • Android開(kāi)發(fā)使用Handler的PostDelayed方法實(shí)現(xiàn)圖片輪播功能

    Android開(kāi)發(fā)使用Handler的PostDelayed方法實(shí)現(xiàn)圖片輪播功能

    這篇文章主要介紹了Android開(kāi)發(fā)使用Handler的PostDelayed方法實(shí)現(xiàn)圖片輪播功能,結(jié)合實(shí)例形式分析了Android基于Handler的PostDelayed方法實(shí)現(xiàn)圖片輪播功能的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-12-12
  • Android 三級(jí)NestedScroll嵌套滾動(dòng)實(shí)踐

    Android 三級(jí)NestedScroll嵌套滾動(dòng)實(shí)踐

    這篇文章主要介紹了Android 三級(jí)NestedScroll嵌套滾動(dòng)實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • Android實(shí)現(xiàn)計(jì)時(shí)器功能

    Android實(shí)現(xiàn)計(jì)時(shí)器功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)計(jì)時(shí)器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-04-04

最新評(píng)論