Android oncreate中获取控件宽高

Android oncreate中获取控件宽高

protected void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.main);  
View view = findViewById(R.id.main_my_view);  
view.post(new Runnable() {    
    // Get size of view after layout  
    @Override  
    public void run() {  
        Log.d(TAG, "view has width: "+view.getWidth() + " and height: "+view.getHeight());  
    }  
});  
} 

你可能感兴趣的:(android,android)