开发者

Why does scrolling a view at activity start only work in a runnable?

开发者 https://www.devze.com 2023-03-08 12:10 出处:网络
Why does doing HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.buttons); if (null != hsv) hsv.scrollBy(iLengthToScroll, 0);

Why does doing

HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.buttons);
if (null != hsv) hsv.scrollBy(iLengthToScroll, 0);              

in onResume do nothing, but

Handler mHandler = new Handler();
Runnable scroll = new Runnable()
{
  @Override
  public void run()
  {
 开发者_运维百科   HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.buttons);
    if (null != hsv) hsv.scrollBy(iLengthToScroll, 0);              
  }
};
mHandler.post(scroll);

do the scrolling? Handler.post adds the runnable to the UI thread, but onResume is already in the UI thread, isn't it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号