How can I catch the view becoming visible

I inflate Views on a ScrollView.

And I need to get an event when, when scrolling, one of these types (the last, for example, or a special type) becomes visible (in the screen area).

+4
source share
3 answers

If the view changes visibility, the onlayout method is called, you can try to rewrite this method and check its status.

0
source

You need to override the onVisibilityChanged() . It is also called when one of the ancestors of a species changes its visibility.

0
source

This I have inflated my GridView and get what you want

 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
source

All Articles