[英]How to listen for Android View transformation change?
我正在創建一個自定義View
,我想聽一下轉換的變化。 例如,由View#setScaleX
觸發的那些。 一種方法是覆蓋所有方法:
我錯過了什么嗎? 我不關心 top/left/bottom/right 屬性,所以它們被故意排除在外。 然而這很麻煩。 如果我能得到一個回調並監聽它會更好。 那可能嗎?
//Make some kind of callback
public interface TransformationCallback{
//String whatWho is an example it can be anything.
void onTransform(String whatWho);
}
public class YourView extends View{
private TransformationCallback callback;
//Pass an interface into the View constructor
public YourView(Context context, TransformationCallback callback){
super(context);
this.callback = callback;
}
}
@Override
public void setTranslationX(float x){
//call onTransform from the callback
callback.onTransform("setTranslationX was called");
super.setTranslationX(x);
}
唯一的問題是它不會檢測到這些函數“設置”的下划線值的內部變化。
例如, View
中有一個名為protected int mLeft;
多次修改,內部不使用函數。
該變量也protected
意味着View
的abstractions
也可以在沒有 function 調用的情況下修改它。
在大多數情況下,只有與Views
混淆的外部類才會使用那些可能會或可能不會影響您的功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.