![](/img/trans.png)
[英]Smooth scroll to position in Android gridview makes work it wrong
[英]Scroll to position without smooth animation on 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 operation
這些都不起作用。 我唯一的解決方法是:
this.gridView.smoothScrollToPositionFromTop(0, 0, 0);
這實際上是滾動的,但是即使我給定的持續時間為0,它仍然會進行簡短的滾動動畫。
我想你的gridView有一個id的網格。 所以如果不添加它
android:id="@+id/grid"
為此,因此在onCreate
方法中調用以下函數:
GridView v = (GridView) findViewById(R.id.grid);
v.requestFocus();
如果上述技巧不起作用,請嘗試將GridView
放入RelativeLayout
,並為
RelativeLayout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.