PullToRefreshScrollView中的Android PullToRefresh库剪辑视图问题

时间:2013-03-15 17:32:23

标签: android

Video of the issue here

Link to the library

视频可能有点难以看清,但正在发生的事情是当我向Activity添加新片段时,ScrollView中的内容很奇怪。而不是平滑地设置动画,创建一个约55像素的额外边距(在720 x 1280手机上),然后在动画完成后进行自我修正。

我挖掘了源代码并发现如果我在PullToRefreshBase类的onSizeChanged()方法中注释这两个方法,动画将正常工作:

@Override
protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (DEBUG) {
        Log.d(LOG_TAG, String.format("onSizeChanged. W: %d, H: %d", w, h));
    }

    super.onSizeChanged(w, h, oldw, oldh);

    //TODO both of these methods below combined cause the glitchy issue

    // We need to update the header/footer when our size changes
    refreshLoadingViewsSize();

    // Update the Refreshable View layout
    refreshRefreshableViewSize(w, h);

    //TODO both of these methods above combined cause the glitchy issue

    /**
     * As we're currently in a Layout Pass, we need to schedule another one
     * to layout any changes we've made here
     */
    post(new Runnable() {
        @Override
        public void run() {
            requestLayout();
        }
    });
}

refreshLoadingViewsSize()和refreshRefreshableViewSize()方法是导致问题的原因。但是,当我评论它们时,PullToRefresh功能不再起作用了。这是因为没有调用设置头大小的第一个方法。这意味着标题高度始终为0,这会破坏下拉功能,该功能依赖于标题的高度来工作。此外,标题本身甚至不会显示,但这不起作用。

不幸的是,只评论一次会使裁剪问题更严重。

我还尝试了一个hacky修复,我只在第一次调用onSizeChanged时运行这两种方法,然后忽略它们。像这样:

if(mFirstGo) {
    // We need to update the header/footer when our size changes
    refreshLoadingViewsSize();

    // Update the Refreshable View layout
    refreshRefreshableViewSize(w, h);

    mFirstGo = false;
}

除了一个问题外,这很有用。添加片段时,填充不正确,因此ScrollView的内容高于应有的内容。这是因为填充是第一次设置,但是永远不会再次重置。这就像填充在整个时间内为0并不是问题,但如果首先设置填充,则每次视图大小更改时都需要继续重置。

我认为这个问题的原因是填充更改的发生与视图更改无关,但我不确定。如果有人在这里有一些见解,我真的很感激。谢谢!

0 个答案:

没有答案