Hy,我正在尝试实现这个动画。有人能帮我吗?
https://www.youtube.com/watch?v=0XfmKq-ihN0&feature=youtu.be
我尝试过使用pull来刷新库,但结果并不像预期的那样。非常感谢。
在android 中为ScrollView添加效果反弹
步骤1:在包com.base.view 中创建新文件BounceScrollView
公共类BouncySoll扩展了ScrollView{private 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"
/>