日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 阻尼动画,Android拉伸阻尼效果实现

發(fā)布時間:2024/9/15 Android 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 阻尼动画,Android拉伸阻尼效果实现 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最主要就這個類:

package com.bluemagee.assistant.app;

import android.content.Context;

import android.graphics.Rect;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.TranslateAnimation;

import android.widget.ScrollView;

public class BounceScrollView extends ScrollView {

private boolean isCalled;

private Callback mCallback;

private View mView;

private Rect mRect = new Rect();

private int y;

private boolean isFirst = true;

public BounceScrollView(Context context, AttributeSet attrs) {

super(context, attrs);

}

@Override

protected void onFinishInflate() {

if (getChildCount() > 0)

mView = getChildAt(0);

super.onFinishInflate();

}

@Override

public boolean onTouchEvent(MotionEvent ev) {

if (mView != null) {

commonOnTouch(ev);

}

return super.onTouchEvent(ev);

}

private void commonOnTouch(MotionEvent ev) {

int action = ev.getAction();

int cy = (int) ev.getY();

switch (action) {

case MotionEvent.ACTION_DOWN:

break;

case MotionEvent.ACTION_MOVE:

int dy = cy - y;

if (isFirst) {

dy = 0;

isFirst = false;

}

y = cy;

if (isNeedMove()) {

if (mRect.isEmpty()) {

mRect.set(mView.getLeft(), mView.getTop(),

mView.getRight(), mView.getBottom());

}

mView.layout(mView.getLeft(), mView.getTop() + 2 * dy / 3,

mView.getRight(), mView.getBottom() + 2 * dy / 3);

if (shouldCallBack(dy)) {

if (mCallback != null) {

if (!isCalled) {

isCalled = true;

resetPosition();

mCallback.callback();

}

}

}

}

break;

case MotionEvent.ACTION_UP:

if (!mRect.isEmpty()) {

resetPosition();

}

break;

}

}

private boolean shouldCallBack(int dy) {

if (dy > 0 && mView.getTop() > getHeight() / 2)

return true;

return false;

}

private void resetPosition() {

Animation animation = new TranslateAnimation(0, 0, mView.getTop(),

mRect.top);

animation.setDuration(200);

animation.setFillAfter(true);

mView.startAnimation(animation);

mView.layout(mRect.left, mRect.top, mRect.right, mRect.bottom);

mRect.setEmpty();

isFirst = true;

isCalled = false;

}

public boolean isNeedMove() {

int offset = mView.getMeasuredHeight() - getHeight();

int scrollY = getScrollY();

if (scrollY == 0 || scrollY == offset) {

return true;

}

return false;

}

public void setCallBack(Callback callback) {

mCallback = callback;

}

public interface Callback

{

void callback();

}

}

總結

以上是生活随笔為你收集整理的android 阻尼动画,Android拉伸阻尼效果实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。