I actually tried a lot to make scroll view
bouncable
but I didn't make it and over internet every thing not work properly I just want bouncable scroll view like ios please if any one can help it will be great
I tried these one `public class BounceScrollView extends ScrollView { private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;
private Context mContext;
private int mMaxYOverscrollDistance;
public BounceScrollView(Context context) {
super(context);
mContext = context;
initBounceScrollView();
}
public BounceScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
initBounceScrollView();
}
public BounceScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
initBounceScrollView();
}
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
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);
}
}` These one of the example that it work but in some point the scroll view stuck and problem similar to that, and other library that are available but didn't work, so like it's possible to make scroll view bouncable or there's no hope?
CodePudding user response:
If you are using SingleChildScrollView
, you can try add BouncingScrollPhysics()
to your widget.
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
alignment: Alignment.center,
width: double.infinity,
height: double.infinity,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(), // add this line
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// your widget
],
),
),
),
),
);
}
CodePudding user response:
Simply use physics: BouncingScrollPhysics()
in your scrolling widget