Why HorizontalScrollView not scroll in HTCDesire 2.2 but only on simulator?
I am using a HorizentalScrollView
in a view. I add TextView
at runtime. I use horView.smoothScrollTo(x,y)
; It works fine for simulator. But it doesn't scroll at HTCDesire 2.2 ? any idea? here my code.
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>
At the end I found solution. I was calling smoothScrollTo(x,y) at the end of on create.(where else I can put that?) problem was that at the time of initializing there was not size or length found(But it should not be, because I have put all the data in that). So call postDealy() with a delay of 50 sec. It works for me. Here is that. I put it at the end of onCreate(); May b anyone else have a batter solution...
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
horView.smoothScrollTo((scrollAmount), 0);
}
}, 50);
You can use View.post to avoid depending on timing.
horView.post(new Runnable() {
public void run() {
horView.smoothScrollTo((scrollAmount), 0);
}
});
This gets executed right after the view has been attached to the screen.
精彩评论