View.post()方法的使用

 
  

public boolean post(Runnable action) {
    final AttachInfo attachInfo = mAttachInfo;
    if (attachInfo != null) {
        return attachInfo.mHandler.post(action);
    }
    // Assume that post will succeed later
    ViewRootImpl.getRunQueue().post(action);
    return true;
}

在view已经添加到窗口时,立即加入执行队列,否则等添加到窗口后,添加到执行队列
 
  
实例:
 
  
@Override
public void onResume() {
    super.onResume();
    if(!mList.isEmpty()){
        // need to call this method from list view handler in order to have list filled previously

        mListView.post(new Runnable() {
            @Override
            public void run() {

                mListItemVisibilityCalculator.onScrollStateIdle(
                        mItemsPositionGetter,
                        mListView.getFirstVisiblePosition(),
                        mListView.getLastVisiblePosition());

            }
        });
    }
}

你可能感兴趣的:(View.post()方法的使用)