自定義具有回彈效果的ScrollView

2021-08-19 20:40:15 字數 1374 閱讀 9079

專案中需要具有回彈效果的scrollview,可設定最大拖動距離,實現回彈效果。

可以用來解決與子布局中的onclick事件衝突問題。

@override

public boolean canscrollvertically(int direction)

public class springbackscrollview extends scrollview 

public springbackscrollview(context context, attributeset attrs)

@override

protected void onfinishinflate()

}//用來處理子布局中onclick事件衝突的

@override

public boolean canscrollvertically(int direction)

@override

public boolean ontouchevent(motionevent ev) else

return super.ontouchevent(ev);

}public void commontouchevent(motionevent ev)

break;

case motionevent.action_move:

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())

int yy = inner.gettop() - deltay;

// 移動布局

inner.layout(inner.getleft(), yy, inner.getright(),

inner.getbottom() - deltay);

}break;

default:

break;}}

// 開啟動畫移動

public void animation()

// 是否需要開啟動畫

public boolean isneedanimation()

// 是否需要移動布局

public boolean isneedmove()

return false;

}}

Scrollview回彈效果自定義控制項

滾動回彈效果分析 首先,建立乙個類,繼承scrollview,重寫ontouch事件,實現伸縮回彈效果。scroollview節點下只能有乙個子節點,這個子節點就是我們要移動的view布局。第一步 獲取要操作的子view布局 第二步 重寫ontouch事件監聽 分析具體事件 觀察分析得出結論 讓布局...

自定義動畫效果

demotitle charset utf 8 src bootstrap js jquery.min.js script div1 style head animateh2 params,speed easing fn p 用於建立自定義動畫的函式。這個函式的關鍵在於指定動畫形式及結果樣式屬性物件...

自定義imageview,實現多點縮放回彈

package laladin.album import android.content.context import android.graphics.bitmap import android.util.floatmath import android.view.motionevent impo...