Hy,我正在尝试实现这个动画。有人能帮助我吗?
https://www.youtube.com/watch?v=0XfmKq-ihN0&feature=youtu.be
我尝试使用pull刷新库,但结果并不像预期的那样。谢谢!
答案 0 :(得分:1)
在Android
中添加效果反弹到ScrollView第1步:在com.base.view包中创建新文件BounceScrollView
public class BouncyScroll扩展ScrollView { 私有ScrollCallbacks mCallbacks;
private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;
private Context mContext;
private int mMaxYOverscrollDistance;
public BouncyScroll(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
initBounceScrollView();
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mCallbacks != null) {
mCallbacks.onScrollChanged(l, t, oldl, oldt);
}
}
@Override
public int computeVerticalScrollRange() {
return super.computeVerticalScrollRange();
}
public void setCallbacks(ScrollCallbacks listener) {
mCallbacks = listener;
}
private void initBounceScrollView() {
// get the density of the screen and do some maths with it on the max
// overscroll distance
// variable so that you get similar behaviors no matter what the screen
// size
final DisplayMetrics metrics = mContext.getResources()
.getDisplayMetrics();
final float density = metrics.density;
mMaxYOverscrollDistance = (int) (density * MAX_Y_OVERSCROLL_DISTANCE);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
}
static interface ScrollCallbacks {
public void onScrollChanged(int l, int t, int oldl, int oldt);
}
@SuppressLint("NewApi")
@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
int scrollY, int scrollRangeX, int scrollRangeY,
int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
// This is where the magic happens, we have replaced the incoming
// maxOverScrollY with our own custom variable mMaxYOverscrollDistance;
return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
scrollRangeX, scrollRangeY, maxOverScrollX,
mMaxYOverscrollDistance, isTouchEvent);
}
} 第2步:在您的布局中,请更改
<ScrollView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
到
<com.base.view.BounceScrollView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>