Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在GridView上滚动到无平滑动画的位置_Android_Gridview - Fatal编程技术网

Android 在GridView上滚动到无平滑动画的位置

Android 在GridView上滚动到无平滑动画的位置,android,gridview,Android,Gridview,我试图立即将GridView移动到一个位置(在我的例子中是网格的开始)。我尝试了以下方法: this.gridView.scrollTo(0, 0); this.gridView.setScrollX(0); this.gridView.setScrollY(0); this.gridView.scrollTo(0, this.gridView.getTop()); this.gridView.computeScroll(); // Doing the previous in a post op

我试图立即将GridView移动到一个位置(在我的例子中是网格的开始)。我尝试了以下方法:

this.gridView.scrollTo(0, 0);
this.gridView.setScrollX(0);
this.gridView.setScrollY(0);
this.gridView.scrollTo(0, this.gridView.getTop());
this.gridView.computeScroll();
// Doing the previous in a post operation
这些都不管用。我唯一的解决办法是:

this.gridView.smoothScrollToPositionFromTop(0, 0, 0);

这实际上是滚动的,但即使我给了持续时间0,它仍然会做一个短滚动动画。

我想你的gridView的id是grid。所以如果它没有,就加上这个

android:id="@+id/grid"
因此,在
onCreate
方法中调用以下函数:

GridView v = (GridView) findViewById(R.id.grid); 

v.requestFocus();
如果上述技巧不起作用,请尝试将您的
GridView
放入
RelativeLayout
中,并对您的用户执行上述技巧


RelativeLayout

您可以尝试此.gridView.setSelection(0);是的,这实际上是我第一次尝试。