Is there any event fired when android View becomes visible within App?

后端 未结 1 1199
小蘑菇
小蘑菇 2021-02-19 03:53

My App contains multiple views (scrollable), one of them is CustomView ( extends View), is there any android event fired when this View comes within visible area.

The ap

相关标签:
1条回答
  • 2021-02-19 04:54

    Here is one sample code using ViewTreeObserver:

    final View viewTemp = convertView;
    
    convertView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
       @Override
       public void onGlobalLayout() {
          int rowHeight = viewTemp.getGlobalVisibleRect();
          ...
       });
    

    Notes:

    • I don't know your code and it is not posted. The code viewTemp = convertView is just an example, code from using an Adapter.
    • This is a listener when the layout is drawn for whatever reason which is many.
    0 讨论(0)
提交回复
热议问题