在onCreate
中是获取不到View的宽高以及坐标的。
使用View.post(Runnable)
可以获取:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View someView = findViewById(R.id.some_view);
someView.post(new Runnable() {
@Override
public void run() {
Log.i(TAG, "x: " + someView.getX() + "y: " + someView.getY() +
" width: " + someView.getWidth() + " height: " + someView.getHeight());
}
});
}