4

我在 ScrollView 上膨胀视图。

而且我需要获取事件,当滚动其中一个视图(例如,最后一个或特殊类型)变得可见时(在屏幕区域中)。

4

3 回答 3

0

如果视图更改可见性,则调用 onlayout 方法,您可以尝试覆盖该方法并检查其状态。

于 2012-12-11T15:49:41.433 回答
0

您需要覆盖视图的onVisibilityChanged(). 当视图的祖先之一更改可见性时,也会调用此方法。

于 2015-07-06T07:45:53.017 回答
-1

这我膨胀了我的 GridView 并得到你想要的

public class MyGrideView extends GridView {

    boolean expanded = false;

    public MyGrideView(Context context) {
        super(context);
    }

    public MyGrideView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyGrideView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded() {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded()) {
            // Calculate entire height by providing a very large height hint.
            // But do not use the highest 2 bits of this integer; those are
            // reserved for the MeasureSpec mode.
            int expandSpec = MeasureSpec.makeMeasureSpec(
                    Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
    }

}
于 2012-12-11T15:26:21.823 回答