在 Android 中,您能否创建一个监听器来捕捉 View 属性的变化(宽度/高度/边距/相对于屏幕顶部的位置)?
我想在 layout_marginTop="10dp"更改为不同的值时触发一个事件。
最佳答案
如何实现一个 OnLayoutChangeListener,当 View 因布局更改而移动时被调用
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
}
});
Android API 摘录:
Add a listener that will be called when the bounds of the view change due to layout processing.
关于Android - 用于捕获 View 属性更改的监听器(例如 android :layout_marginTop),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19248628/