我怎样才能看到该视图变得可见

时间:2022-10-28 13:22:48

I inflate Views on ScrollView.

我在ScrollView上膨胀视图。

And I need to get event, when on scrolling one of this Views (last, for example, or special type) becomes visible (in screen zone).

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

3 个解决方案

#1


0  

If a view changes visibility, the onlayout method is called, you could try overwriting that method and check it's state.

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

#2


0  

You need to override the view's onVisibilityChanged(). This is also called when one of the view's ancestors changes visibility.

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

#3


-1  

This I inflated my GridView and get what you want

这让我膨胀了我的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;
    }

}

#1


0  

If a view changes visibility, the onlayout method is called, you could try overwriting that method and check it's state.

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

#2


0  

You need to override the view's onVisibilityChanged(). This is also called when one of the view's ancestors changes visibility.

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

#3


-1  

This I inflated my GridView and get what you want

这让我膨胀了我的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;
    }

}