滚动查看android工作室边界电缆



我实际上尝试了很多来制作滚动视图

可绑定

但我没有成功,在互联网上一切都不正常工作,我只想要像ios一样的有边界滚动视图,如果有人能帮助的话,那将是很棒的

我试过这个`公共类BounceScrollView扩展了ScrollView{private static最终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);
}

}`这是一个可以工作的例子,但在某些方面滚动视图卡住了,问题与此类似,还有其他可用但不起作用的库,所以可以使滚动视图具有可绑定性,还是没有希望?

如果使用SingleChildScrollView,可以尝试将BouncingScrollPhysics()添加到小部件中。

@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
],
),
),
),
),
);
}

只需在滚动小部件中使用physics: BouncingScrollPhysics()

最新更新