最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 實(shí)現(xiàn)圓圈擴(kuò)散水波動(dòng)畫效果兩種方法

 更新時(shí)間:2018年05月28日 08:58:52   作者:程序猿tx  
這篇文章主要介紹了Android 實(shí)現(xiàn)圓圈擴(kuò)散水波動(dòng)畫效果兩種方法,需要的朋友可以參考下

兩種方式實(shí)現(xiàn)類似水波擴(kuò)散效果,先上圖為敬

  1. 自定義view實(shí)現(xiàn)
  2. 動(dòng)畫實(shí)現(xiàn)

自定義view實(shí)現(xiàn)

思路分析:通過(guò)canvas畫圓,每次改變圓半徑和透明度,當(dāng)半徑達(dá)到一定程度,再次從中心開始繪圓,達(dá)到不同層級(jí)的效果,通過(guò)不斷繪制達(dá)到view擴(kuò)散效果

private Paint centerPaint; //中心圓paint
private int radius = 100; //中心圓半徑
private Paint spreadPaint; //擴(kuò)散圓paint
private float centerX;//圓心x
private float centerY;//圓心y
private int distance = 5; //每次圓遞增間距
private int maxRadius = 80; //最大圓半徑
private int delayMilliseconds = 33;//擴(kuò)散延遲間隔,越大擴(kuò)散越慢
private List<Integer> spreadRadius = new ArrayList<>();//擴(kuò)散圓層級(jí)數(shù),元素為擴(kuò)散的距離
private List<Integer> alphas = new ArrayList<>();//對(duì)應(yīng)每層圓的透明度

style文件里自定義屬性

<declare-styleable name="SpreadView">
  <!--中心圓顏色-->
  <attr name="spread_center_color" format="color" />
  <!--中心圓半徑-->
  <attr name="spread_radius" format="integer" />
  <!--擴(kuò)散圓顏色-->
  <attr name="spread_spread_color" format="color" />
  <!--擴(kuò)散間距-->
  <attr name="spread_distance" format="integer" />
  <!--擴(kuò)散最大半徑-->
  <attr name="spread_max_radius" format="integer" />
  <!--擴(kuò)散延遲間隔-->
  <attr name="spread_delay_milliseconds" format="integer" />
</declare-styleable>

初始化

public SpreadView(Context context) {
  this(context, null, 0);
}
public SpreadView(Context context, @Nullable AttributeSet attrs) {
  this(context, attrs, 0);
}
public SpreadView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpreadView, defStyleAttr, 0);
  radius = a.getInt(R.styleable.SpreadView_spread_radius, radius);
  maxRadius = a.getInt(R.styleable.SpreadView_spread_max_radius, maxRadius);
  int centerColor = a.getColor(R.styleable.SpreadView_spread_center_color, ContextCompat.getColor(context, R.color.colorAccent));
  int spreadColor = a.getColor(R.styleable.SpreadView_spread_spread_color, ContextCompat.getColor(context, R.color.colorAccent));
  distance = a.getInt(R.styleable.SpreadView_spread_distance, distance);
  a.recycle();
  centerPaint = new Paint();
  centerPaint.setColor(centerColor);
  centerPaint.setAntiAlias(true);
  //最開始不透明且擴(kuò)散距離為0
  alphas.add(255);
  spreadRadius.add(0);
  spreadPaint = new Paint();
  spreadPaint.setAntiAlias(true);
  spreadPaint.setAlpha(255);
  spreadPaint.setColor(spreadColor);
}

確定圓心位置

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);
  //圓心位置
  centerX = w / 2;
  centerY = h / 2;
}

自定義view的繪制

@Override
protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  for (int i = 0; i < spreadRadius.size(); i++) {
    int alpha = alphas.get(i);
    spreadPaint.setAlpha(alpha);
    int width = spreadRadius.get(i);
    //繪制擴(kuò)散的圓
    canvas.drawCircle(centerX, centerY, radius + width, spreadPaint);
    //每次擴(kuò)散圓半徑遞增,圓透明度遞減
    if (alpha > 0 && width < 300) {
      alpha = alpha - distance > 0 ? alpha - distance : 1;
      alphas.set(i, alpha);
      spreadRadius.set(i, width + distance);
    }
  }
  //當(dāng)最外層擴(kuò)散圓半徑達(dá)到最大半徑時(shí)添加新擴(kuò)散圓
  if (spreadRadius.get(spreadRadius.size() - 1) > maxRadius) {
    spreadRadius.add(0);
    alphas.add(255);
  }
  //超過(guò)8個(gè)擴(kuò)散圓,刪除最先繪制的圓,即最外層的圓
  if (spreadRadius.size() >= 8) {
    alphas.remove(0);
    spreadRadius.remove(0);
  }
  //中間的圓
  canvas.drawCircle(centerX, centerY, radius, centerPaint);
  //TODO 可以在中間圓繪制文字或者圖片
  //延遲更新,達(dá)到擴(kuò)散視覺(jué)差效果
  postInvalidateDelayed(delayMilliseconds);
}

xml樣式

<com.airsaid.diffuseview.widget.SpreadView
  android:id="@+id/spreadView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:spread_center_color="@color/colorAccent"
  app:spread_delay_milliseconds="35"
  app:spread_distance="5"
  app:spread_max_radius="90"
  app:spread_radius="100"
  app:spread_spread_color="@color/colorAccent" />

效果圖

中心圓處可以自定義寫文字,畫圖片等等...

動(dòng)畫實(shí)現(xiàn)

思路分析:通過(guò)動(dòng)畫實(shí)現(xiàn),imageView不停做動(dòng)畫縮放+漸變

最中心的imageView保持不變

中間一層imageView從原始放大到1.4倍,同時(shí)從不透明變?yōu)榘胪该?/p>

最外層的imageView從1.4倍放大到1.8倍,同時(shí)從半透明變?yōu)槿该?/p>

利用shape畫一個(gè)圓,作為動(dòng)畫基礎(chǔ)視圖

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <corners android:radius="65dp"/>
  <solid android:color="@color/colorAccent"/>
</shape>

布局視圖

<FrameLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <!--中心imageView-->
  <ImageView
    android:id="@+id/iv_wave"
    android:layout_width="130dp"
    android:layout_height="130dp"
    android:layout_gravity="center"
    android:background="@drawable/shape_circle" />
  <!--中間的imageView-->
  <ImageView
    android:id="@+id/iv_wave_1"
    android:layout_width="130dp"
    android:layout_height="130dp"
    android:layout_gravity="center"
    android:background="@drawable/shape_circle" />
  <!--最外層imageView-->
  <ImageView
    android:id="@+id/iv_wave_2"
    android:layout_width="130dp"
    android:layout_height="130dp"
    android:layout_gravity="center"
    android:background="@drawable/shape_circle" />
</FrameLayout>

中間imageView的動(dòng)畫

private void setAnim1() {
  AnimationSet as = new AnimationSet(true);
  //縮放動(dòng)畫,以中心從原始放大到1.4倍
  ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.4f, 1.0f, 1.4f,
      ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
      ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
  //漸變動(dòng)畫
  AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);
  scaleAnimation.setDuration(800);
  scaleAnimation.setRepeatCount(Animation.INFINITE);
  alphaAnimation.setRepeatCount(Animation.INFINITE);
  as.setDuration(800);
  as.addAnimation(scaleAnimation);
  as.addAnimation(alphaAnimation);
  iv1.startAnimation(as);
}

最外層imageView的動(dòng)畫

private void setAnim2() {
  AnimationSet as = new AnimationSet(true);
  //縮放動(dòng)畫,以中心從1.4倍放大到1.8倍
  ScaleAnimation scaleAnimation = new ScaleAnimation(1.4f, 1.8f, 1.4f, 1.8f,
      ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
      ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
  //漸變動(dòng)畫
  AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 0.1f);
  scaleAnimation.setDuration(800);
  scaleAnimation.setRepeatCount(Animation.INFINITE);
  alphaAnimation.setRepeatCount(Animation.INFINITE);
  as.setDuration(800);
  as.addAnimation(scaleAnimation);
  as.addAnimation(alphaAnimation);
  iv2.startAnimation(as);
}

效果圖

相比較而言,自定義view的效果更好點(diǎn),動(dòng)畫實(shí)現(xiàn)起來(lái)更方便點(diǎn)。

兩種方式實(shí)現(xiàn)的擴(kuò)散效果介紹完畢,具體項(xiàng)目里還是要按需變動(dòng)的。

總結(jié)

以上所述是小編給大家介紹的Android 實(shí)現(xiàn)圓圈擴(kuò)散水波動(dòng)畫效果兩種方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • android實(shí)現(xiàn)快遞跟蹤進(jìn)度條

    android實(shí)現(xiàn)快遞跟蹤進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)快遞跟蹤進(jìn)度條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android使用Messenger實(shí)現(xiàn)service與activity交互

    Android使用Messenger實(shí)現(xiàn)service與activity交互

    這篇文章主要介紹了android使用Messenger實(shí)現(xiàn)service與activity交互的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • Android鍵盤自動(dòng)彈出解決方法分析

    Android鍵盤自動(dòng)彈出解決方法分析

    這篇文章主要介紹了Android鍵盤自動(dòng)彈出解決方法,結(jié)合實(shí)例形式對(duì)比分析了三種解決方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-01-01
  • Android 廣播大全 Intent Action 事件詳解

    Android 廣播大全 Intent Action 事件詳解

    這篇文章主要給大家介紹Android 廣播大全 Intent Action 事件詳解,涉及到android廣播action 方面知識(shí)點(diǎn),本文講解的非常的全面,感興趣的朋友一起看看吧
    2015-10-10
  • 利用flutter實(shí)現(xiàn)炫酷的list

    利用flutter實(shí)現(xiàn)炫酷的list

    這篇文章主要給大家介紹了關(guān)于利用flutter實(shí)現(xiàn)炫酷的list的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Android仿微信語(yǔ)音聊天功能

    Android仿微信語(yǔ)音聊天功能

    這篇文章主要介紹了Android仿微信語(yǔ)音聊天功能,很實(shí)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android ItemDecoration 實(shí)現(xiàn)分組索引列表的示例代碼

    Android ItemDecoration 實(shí)現(xiàn)分組索引列表的示例代碼

    本篇文章主要介紹了Android ItemDecoration 實(shí)現(xiàn)分組索引列表的示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-10-10
  • Android 自定義dialog的實(shí)現(xiàn)代碼

    Android 自定義dialog的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 自定義dialog的實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android Fragment使用之實(shí)例演示

    Android Fragment使用之實(shí)例演示

    本文主要介紹Android Fragment的知識(shí),這里整理了詳細(xì)資料及簡(jiǎn)單示例代碼,有需要的朋友可以參考下
    2016-09-09
  • Kotlin開發(fā)中與if等價(jià)的takeIf與takeUnless詳解

    Kotlin開發(fā)中與if等價(jià)的takeIf與takeUnless詳解

    這篇文章主要介紹了Kotlin開發(fā)中與if等價(jià)的takeIf與takeUnless使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2023-01-01

最新評(píng)論

响水县| 阳江市| 宣武区| 保定市| 蒙自县| 准格尔旗| 辽宁省| 嘉义县| 芒康县| 铜梁县| 如皋市| 太康县| 柳林县| 德令哈市| 治县。| 治多县| 库尔勒市| 哈巴河县| 吉木乃县| 秀山| 洛浦县| 阿克| 瑞丽市| 自贡市| 高密市| 舞钢市| 蒙山县| 凯里市| 新化县| 临颍县| 常德市| 武宁县| 双柏县| 扎兰屯市| 株洲市| 德令哈市| 靖安县| 江山市| 广西| 望城县| 湄潭县|