如何正确获取View的宽高

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());
            }
        });
    }

你可能感兴趣的:(如何正确获取View的宽高)