问题
I am building an application that needs to refresh the UI every time view bounds changes.
I tried the view.addOnLayoutChangeListener()
but it called a lot of times.
As wrote in the answer it happens because I didn't remove the LayoutChangeListener
, But I want to keep it for the next events.
So my question is:
How can I listen for several LayoutChange
events (not only for the first one)?
code:
int counter=0;
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
Toast.makeText(getContext(),++counter+"",Toast.LENGTH_SHORT).show(); //goes to infinity
}
});
I read this answer too, but it requires to create a new subclass.
Can the onSizeChanged
for the layout help me in this situation?
来源:https://stackoverflow.com/questions/65831475/how-to-listen-for-several-layoutchange-calls