Override Zoom Over Swipetorefresh - Android
Okay so if I have scrolled just a little bit and the swipetorefresh gets visible, and if I try to zoom with two fingers it just gets further down to refresh. What I want to achiev
Solution 1:
I had the same issue and I successfully solved it with next:
Create new class extended from SwipeRefreshLayout
publicclassSwipeToRefreshextendsSwipeRefreshLayout {
privatestaticfinalfloatREFRESH_RATE=10f;
privatefloat mDownX, mDownY, scaleX, scaleY;
publicSwipeToRefresh(Context context) {
super(context);
}
publicSwipeToRefresh(Context context, AttributeSet attrs) {
super(context, attrs);
}
@OverridepublicbooleanonInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mDownX = ev.getX();
mDownY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
return doRefresh(ev);
case MotionEvent.ACTION_UP:
return doRefresh(ev);
}
returnsuper.onInterceptTouchEvent(ev);
}
privatebooleandoRefresh(MotionEvent ev) {
scaleX = Math.abs(ev.getX() - mDownX);
scaleY = Math.abs(ev.getY() - mDownY);
if (scaleY / scaleX > REFRESH_RATE) {
returnsuper.onInterceptTouchEvent(ev);
} else {
returnfalse;
}
}
}
In activity
SwipeToRefreshmSwipeRefreshLayout= (SwipeToRefresh) findViewById(R.id.my_refresh_layout);
mSwipeRefreshLayout.setOnRefreshListener(newSwipeRefreshLayout.OnRefreshListener() {
@OverridepublicvoidonRefresh() {
// Refresh WebView
}
});
Donn't forget change class name in layout
<com.example.package.SwipeToRefresh
android:id="@+id/my_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true" />
</com.example.package.SwipeToRefresh>
Good luck!
Post a Comment for "Override Zoom Over Swipetorefresh - Android"