重绘child到指定位置(上下位置)

	public void offsetChildrenTopAndBottom(int offset, int position) {
 		final int count = getChildCount();

		for (int i = 0; i < count; i++) {
			
			final View v = getChildAt(i);
			
			int top = v.getTop();
			top += offset;
			
			int bottom = v.getBottom();
			bottom += offset;
			
			v.layout(v.getLeft(), top, v.getRight(), bottom);

			invalidate();
		}
	}


将此child 移动offset距离,然后更新界面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要让`ListView`在水平方向滚动到指定位置,可以使用`ScrollController`。可以通过创建一个`ScrollController`对象并将其传递给`ListView`的`controller`属性来实现。然后,使用`animateTo`方法来滚动到指定位置。 以下是一个示例代码: ```dart class MyListView extends StatefulWidget { @override _MyListViewState createState() => _MyListViewState(); } class _MyListViewState extends State<MyListView> { final ScrollController _scrollController = ScrollController(); final double _itemExtent = 100.0; final int _itemCount = 20; @override Widget build(BuildContext context) { return ListView.builder( scrollDirection: Axis.horizontal, controller: _scrollController, itemExtent: _itemExtent, itemCount: _itemCount, itemBuilder: (BuildContext context, int index) { return Container( width: _itemExtent, height: _itemExtent, color: Colors.blue, child: Center( child: Text( 'Item $index', style: TextStyle( color: Colors.white, fontSize: 20.0, ), ), ), ); }, ); } void scrollToIndex(int index) { _scrollController.animateTo( index * _itemExtent, duration: Duration(milliseconds: 500), curve: Curves.easeInOut, ); } } ``` 在上面的示例中,我们使用`ScrollController`来实现`scrollToIndex`方法。在此方法中,我们使用`animateTo`方法将`ListView`滚动到指定位置。注意,我们需要将偏移量乘以`itemExtent`(每个列表项的大小)来得到正确的位置。在实际使用中,我们可以在需要时调用`scrollToIndex`方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值