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

こ雲淡風輕ζ 提交于 2019-12-23 09:26:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!