2011-03-01 36 views
1

我在視圖中使用了HorizentalScrollView。我在運行時添加TextView。我用horView.smoothScrollTo(x,y);它適用於模擬器。但它不會在HTCDesire 2.2中滾動?任何想法?在這裏我的代碼。爲什麼Horizo​​ntalScrollView不能在HTCDesire 2.2中滾動,而只能在模擬器上滾動?

horView.smoothScrollTo(num, 0); 


<HorizontalScrollView 
    android:id="@+id/cate_head" 
    android:scrollbars="none" 
    android:foregroundGravity="fill_horizontal" 
    android:layout_width="fill_parent" 
    android:paddingTop="6dip" 
    android:background="@drawable/slider_background" 
    android:focusable="true" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:id="@+id/cate_head_list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center_horizontal" 
     android:orientation="horizontal" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="10dip"> 
    </LinearLayout> 
</HorizontalScrollView> 

回答

1

最後我找到了解決辦法。我在創建結束時調用了smoothScrollTo(x,y)(我可以在哪裏放置它?)問題是,在初始化時沒有找到大小或長度(但它不應該是因爲我有把所有的數據放在那)。 因此,請以50秒的延遲時間致電postDealy()。這個對我有用。這是那個。我把它放在onCreate()的末尾; 可能b別人有連擊的解決方案...

new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      horView.smoothScrollTo((scrollAmount), 0); 
     } 
    }, 50); 
+0

+1和謝謝艾斯蘭對於解決方案... – 2012-03-11 08:34:27

1

您可以使用View.post避免因時機。

horView.post(new Runnable() { 
    public void run() { 
     horView.smoothScrollTo((scrollAmount), 0);   
    } 
}); 

這會在視圖附加到屏幕後立即執行。

+0

我見過的最佳答案(和/或技巧) – hrules6872 2013-09-24 12:42:09

相關問題