问题
In Android, can you create a Listener for catching changes in a View's properties (width / height / margin / position relative to top of the screen)?
I want to trigger an event when layout_marginTop="10dp" is changed to a different value.
回答1:
What about implementing a OnLayoutChangeListener that gets called when a View is moved due to Layout Change
new View().addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom) {
// TODO Auto-generated method stub
}
});
Excerpt from Android API:
Add a listener that will be called when the bounds of the view change due to layout processing.
来源:https://stackoverflow.com/questions/19248628/android-listener-for-catching-changes-in-a-views-properties-e-g-androidlay