Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Listener for catching changes in a View's properties (e.g. android:layout_marginTop)

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.

like image 376
Jack Avatar asked Oct 08 '13 13:10

Jack


1 Answers

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.

like image 67
chuck258 Avatar answered Oct 22 '22 15:10

chuck258