国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

Android 實(shí)現(xiàn)的下拉刷新效果

瀏覽:41日期:2022-09-17 17:46:51

下面是自己實(shí)現(xiàn)的效果:

Android 實(shí)現(xiàn)的下拉刷新效果

1、分析

可以將動(dòng)畫分解成:

睜眼毛驢繞著中心地球旋轉(zhuǎn),并且在到達(dá)地球中心時(shí),切換為閉眼毛驢,最后發(fā)射出去

地球自我旋轉(zhuǎn),隨著下拉而緩緩上升,達(dá)到半徑距離后停止上升

一顆上下來回移動(dòng)的衛(wèi)星

2、實(shí)現(xiàn)

(1)下載趕集app,然后將其后綴名改為zip解壓獲取我們需要的資源圖片:

Android 實(shí)現(xiàn)的下拉刷新效果

(2) 我們先實(shí)現(xiàn)衛(wèi)星的上下移動(dòng)

核心代碼:

@Override protected void onDraw(Canvas canvas) {super.onDraw(canvas);Matrix matrixPlanet = new Matrix();matrixPlanet.setScale(0.4f, 0.4f);matrixPlanet.postTranslate(locationX / 2 * 3, locationY /4);matrixPlanet.postTranslate(0, upDateY);canvas.drawBitmap(flyingPlanet,matrixPlanet,null); } public void startTranslatePlanet(int duration){ValueAnimator valueAnimator = new ValueAnimator();valueAnimator.setFloatValues(-50.0f, 50.0f);valueAnimator.setDuration(duration);valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) {upDateY = (float) animation.getAnimatedValue();invalidate(); }});valueAnimator.setRepeatCount(ValueAnimator.INFINITE);valueAnimator.setRepeatMode(ValueAnimator.REVERSE);valueAnimator.setInterpolator(new LinearInterpolator());valueAnimator.start(); }

思想:使用Matrix來設(shè)置圖形變換,調(diào)用setScale()設(shè)置Bitmap縮放大小,然后調(diào)用postTranslate()將Bitmap平移到衛(wèi)星的初始位置。最后使用ValueAnimator計(jì)算衛(wèi)星上下移動(dòng)的距離,再調(diào)用postTranslate()即可。

(3)地球自我旋轉(zhuǎn),隨著下拉而緩緩上升,達(dá)到半徑距離后停止上升。

核心代碼:

@Override protected void onDraw(Canvas canvas) {super.onDraw(canvas);Matrix matrixBall = new Matrix();matrixBall.setScale(0.2f, 0.2f);if ((locationY + upDateY) > (locationY - flyingBall_Height / 2)) { matrixBall.postTranslate(locationX - flyingBall_Width / 2, locationY + upDateY); matrixBall.postRotate(degreeBall, locationX, (locationY +upDateY + flyingBall_Height /2) );}else { matrixBall.postTranslate(locationX - flyingBall_Width / 2, locationY - flyingBall_Height / 2); matrixBall.postRotate(degreeBall, locationX, locationY);}canvas.drawBitmap(flyingBall, matrixBall, null);canvas.drawBitmap(cloudBig , null , rectfCloudBig , null);canvas.drawBitmap(cloudSmall , null , rectfCloudSmall ,null); } public void startBallAnim(long duration) {ValueAnimator valueAnimator = new ValueAnimator();valueAnimator.setFloatValues(0.0f, 360.0f);valueAnimator.setDuration(duration);valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) {degreeBall = (float) animation.getAnimatedValue();invalidate(); }});valueAnimator.setRepeatCount(ValueAnimator.INFINITE);valueAnimator.setInterpolator(new LinearInterpolator());valueAnimator.start(); } public void UpBall(float offsetY){if (upDateY!=offsetY) { upDateY = offsetY; invalidate();} } public void accelerateBall(long duration) {clearAnimation();startBallAnim(duration); }

思想:同樣使用Matrix,先設(shè)置縮放大小。調(diào)用

matrixBall.postTranslate(locationX - flyingBall_Width / 2, locationY + upDateY);

將bitmap隱藏在view可視范圍的下方,然后通過下拉刷新列表獲取下拉刷新的Y坐標(biāo)的改變量,調(diào)用postTranslate()上移改變量大小的距離即可。自轉(zhuǎn)動(dòng)畫的實(shí)現(xiàn),就是調(diào)用postRotate()方法 使用ValueAnimator 獲取改變量。因?yàn)榈厍蚴巧仙模晕覀冃枰獎(jiǎng)討B(tài)的設(shè)置旋轉(zhuǎn)的中心。

matrixBall.postRotate(degreeBall, locationX, (locationY +upDateY + flyingBall_Height /2) );

只需要改變減去下拉刷新列表獲取下拉刷新的Y坐標(biāo)的改變量就可以了。

(3) 睜眼毛驢繞著中心地球旋轉(zhuǎn),并且在到達(dá)地球中心時(shí),切換為閉眼毛驢,最后發(fā)射出去

核心代碼:

@Override protected void onDraw(Canvas canvas) {super.onDraw(canvas);Matrix matrix = new Matrix();matrix.setScale(0.3f, 0.3f);matrix.postTranslate(pointDonkey.getDx(), pointDonkey.getDy());matrix.postRotate(degree, locationX, locationY + flyingBall_Width / 2);matrix.postTranslate(0 , upDateY);canvas.drawBitmap(flyingDonkey, matrix, null); }

思想:與上面一樣,先調(diào)用setScale()設(shè)置縮放大小,在進(jìn)行平移旋轉(zhuǎn)操作的時(shí)候。

matrix.postRotate(degree, locationX, locationY + flyingBall_Width / 2); matrix.postTranslate(0 , upDateY);

我們先繞著還沒有移動(dòng)的地球旋轉(zhuǎn),然后調(diào)用postTranslate()將其與地球一起上升。

源碼地址:

https://github.com/sangenan/DonkeyRefresh

到這里就結(jié)束啦。

以上就是Android 實(shí)現(xiàn)的下拉刷新效果的詳細(xì)內(nèi)容,更多關(guān)于Android 下拉刷新的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 杭锦后旗| 长宁县| 特克斯县| 三门峡市| 丹凤县| 石渠县| 确山县| 仲巴县| 法库县| 湖口县| 平陆县| 砀山县| 英超| 尼玛县| 南召县| 大港区| 汶上县| 九寨沟县| 林州市| 长乐市| 永靖县| 安远县| 太白县| 察雅县| 县级市| 荆门市| 沂水县| 探索| 迁安市| 祁连县| 秦安县| 榆林市| 筠连县| 将乐县| 镇坪县| 平陆县| 岳阳县| 岑巩县| 师宗县| 什邡市| 英吉沙县|