av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android自定義View實(shí)現(xiàn)抖音飄動(dòng)紅心效果

瀏覽:119日期:2022-06-06 18:37:30

本文實(shí)例為大家分享了Android自定義View實(shí)現(xiàn)抖音飄動(dòng)紅心效果的具體代碼,供大家參考,具體內(nèi)容如下

自定義View——抖音飄動(dòng)紅心

效果展示

動(dòng)畫(huà)效果

使用自定義view完成紅心飄動(dòng)效果

Android自定義View實(shí)現(xiàn)抖音飄動(dòng)紅心效果

View實(shí)現(xiàn)

動(dòng)畫(huà):屬性動(dòng)畫(huà)(位移+縮放+透明度+旋轉(zhuǎn))+隨機(jī)數(shù):(屬性動(dòng)畫(huà)參數(shù)+顏色選取)

View

/** * 飄心效果 * 1.創(chuàng)建ImageView * 2.ImageView執(zhí)行組合動(dòng)畫(huà) * 3.動(dòng)畫(huà)執(zhí)行完成后銷毀View */public class FlyHeartView extends RelativeLayout { private int defoutWidth = 200;//默認(rèn)控件寬度 private long mDuration = 3000;//默認(rèn)動(dòng)畫(huà)時(shí)間 //顏色集合 從中獲取顏色 private int[] color = { 0xFFFF34B3, 0xFF9ACD32, 0xFF9400D3, 0xFFEE9A00, 0xFFFFB6C1, 0xFFDA70D6, 0xFF8B008B, 0xFF4B0082, 0xFF483D8B, 0xFF1E90FF, 0xFF00BFFF, 0xFF00FF7F }; public FlyHeartView(Context context) { super(context); initFrameLayout(); } public FlyHeartView(Context context, AttributeSet attrs) { super(context, attrs); initFrameLayout(); } private void initFrameLayout() { ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(defoutWidth, ViewGroup.LayoutParams.WRAP_CONTENT); setLayoutParams(params); } /** * 創(chuàng)建一個(gè)心形的view視圖 */ private ImageView createHeartView() { ImageView heartIv = new ImageView(getContext()); LayoutParams params = new LayoutParams(defoutWidth / 2, defoutWidth / 2); //控件位置 params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.CENTER_HORIZONTAL); heartIv.setLayoutParams(params); heartIv.setImageResource(R.mipmap.ic_heart); //改變顏色 heartIv.setImageTintList(ColorStateList.valueOf(color[(int) (color.length * Math.random())])); return heartIv; } /** * 執(zhí)行動(dòng)畫(huà) * 在展示調(diào)用該方法 */ public void startFly() { final ImageView heartIv = createHeartView(); addView(heartIv); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(createTranslationX(heartIv)).with(createTranslationY(heartIv)).with(createScale(heartIv)).with(createRotation(heartIv)).with(createAlpha(heartIv)); //執(zhí)行動(dòng)畫(huà) animatorSet.start(); //銷毀view animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) {super.onAnimationEnd(animation);removeView(heartIv); } }); } /** * 橫向正弦位移動(dòng)畫(huà) * * @return */ private Animator createTranslationX(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, 'translationX', 0, (float) (defoutWidth * Math.random() / 4)); animator.setDuration(mDuration); //CycleInterpolator cycles 正弦曲線數(shù) animator.setInterpolator(new CycleInterpolator((float) (3 * Math.random()))); return animator; } /** * 縱向加速位移動(dòng)畫(huà) * * @return */ private Animator createTranslationY(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, 'translationY', 0, -1000); animator.setDuration(mDuration); animator.setInterpolator(new AccelerateInterpolator()); return animator; } /** * 加速放大動(dòng)畫(huà) * * @return */ private Animator createScale(View view) { ObjectAnimator animatorX = ObjectAnimator.ofFloat(view, 'scaleX', 1, 1.5f); ObjectAnimator animatorY = ObjectAnimator.ofFloat(view, 'scaleY', 1, 1.5f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(mDuration); animatorSet.setInterpolator(new AccelerateInterpolator()); animatorSet.play(animatorX).with(animatorY); return animatorSet; } /** * 透明度動(dòng)畫(huà) * * @return */ private Animator createAlpha(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, 'alpha', 1, 0.1f); animator.setDuration(mDuration); animator.setInterpolator(new AccelerateInterpolator()); return animator; } /** * 旋轉(zhuǎn)動(dòng)畫(huà) * * @return */ private Animator createRotation(View view) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, 'rotation', 0, (float) (25f * Math.random())); animator.setDuration(mDuration); animator.setInterpolator(new CycleInterpolator((float) (6 * Math.random()))); return animator; }}

最后在MainActivity中調(diào)用FlyHeartView 的startFly()方法就能實(shí)現(xiàn)點(diǎn)擊飄心效果。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: 抖音
相關(guān)文章:
主站蜘蛛池模板: 国产午夜精品视频 | 在线色网 | 日本超碰 | 欧美精品a∨在线观看不卡 欧美日韩中文字幕在线播放 | www.4虎影院| 久久精品国产亚洲a | 97超碰在线免费 | 久久婷婷色 | 中文字幕一区二区三区四区五区 | www.啪啪.com| 精品国产精品三级精品av网址 | 亚洲色图综合 | 日本欧美黄色片 | 欧美videosex性极品hd | 91九色视频在线 | 国产精品视频在线播放 | 欧美日韩亚 | 狠狠操在线 | 99热在这里只有精品 | 欧美日韩一区二区视频在线观看 | 日韩影音| 成年人黄色一级片 | av高清毛片| 中文字幕免费在线观看 | 成人网视频 | 成人a视频在线观看 | 成人做爰69片免费观看 | 亚洲一二三区精品 | 久久精品亚洲欧美日韩精品中文字幕 | 久久精品亚洲一区 | 99久久久99久久国产片鸭王 | 在线观看涩涩视频 | 国产精品a级 | 国产精品久久影院 | 久久69精品久久久久久久电影好 | 欧美精品a∨在线观看不卡 国产精品久久国产精品 | 日韩av免费看 | 欧美一级艳情片免费观看 | 亚洲精品一区中文字幕乱码 | 亚洲 欧美 另类 综合 偷拍 | 中文字幕乱码一区二区三区 |