バウンス効果の実装
5100 ワード
リバウンド効果は主にカスタムscrollviewです
0スライド下部と上部の円弧シャドウ効果を除去し、xmlファイルに次の文を追加します.
1.まず2つの変数を定義する
次の方法が必要です
0スライド下部と上部の円弧シャドウ効果を除去し、xmlファイルに次の文を追加します.
android:fadingEdge="none"
android:overScrollMode="never"
1.まず2つの変数を定義する
private View sonView ;--
private Rect normal = new Rect();--
次の方法が必要です
@Override// -- protected void onFinishInflate() { if (getChildCount() > 0) { sonView = getChildAt(0); } }
これは、シフトアニメーションをロードする方法です.
ここでは以下の説明が必要です.
1.Rectでロード可能か否かを判断する
normal.setEmpty();
2シフトアニメーションにはバグがあり、画像はシフトしているが、viewの位置は元の場所にある(imoocではObjectAnimator.ofFloat(imageView、「transLationY」、0 f、100 f).setDuring(200).start()プロパティアニメーションの方法)なので、シフトアニメーションはlayoutで終了する最新の位置を再設定する必要があります.public void animation() { // TranslateAnimation ta = new TranslateAnimation(0, 0, sonView.getTop(), normal.top); ta.setDuration(200); sonView.startAnimation(ta); // sonView.layout(normal.left, normal.top, normal.right, normal.bottom); normal.setEmpty(); }
3.toucheventでイベントを処理する
down:初期位置を記録する
y = ev.getY();
up:リバウンドアニメーション
if (isNeedAnimation()) { //Log.v("mlguitar", "will up and animation"); animation(); }
move:rectの機能は、セカンダリストレージsonviewビューに似ています.
final float preY = y; float nowY = ev.getY();/***size=4は、ドラッグした距離が画面の高さの1/4*/int deltaY=(int)(preY-nowY)/sizeであることを示します.//スクロール//scrollBy(0,deltaY); y = nowY;//一番上または一番下にスクロールするとスクロールしません.このときレイアウトif(isNeedMove(){if(normal.isEmpty()}//通常のレイアウト位置normal.set(sonView.getLeft()、sonView.getTop()、sonView.getRight()を移動, sonView.getBottom()); return; } int yy = sonView.getTop() - deltaY;//レイアウトを移動layout(sonView.getLeft(), yy, sonView.getRight(), sonView.getBottom() - deltaY); }
4次は2つの補助的な方法です// public boolean isNeedAnimation() { return !normal.isEmpty(); } // public boolean isNeedMove() { int offset = sonView.getMeasuredHeight() - getHeight(); int scrollY = getScrollY(); if (scrollY == 0 || scrollY == offset) { return true; } return false; }