2016-05-24 78 views

回答

0

您可以覆蓋onWindowFocusChanged方法和裏面就可以計算出CheckBox寬度/高度編程

@Override 
public void onWindowFocusChanged(boolean hasFocus) { 
    super.onWindowFocusChanged(hasFocus); 

    int checkBoxWidthInPx = mCheckBox.getWidth(); // return the width of your checkbox, in pixels. 
    int checkBoxHeightInPx = mCheckBox.getHeight(); 

    // conver px to dp 
    int checkBoxWidthInDp = checkBoxWidthInPx/this.getResources().getDisplayMetrics().density 
    int checkBoxHeightInDp = checkBoxHeightInPx/this.getResources().getDisplayMetrics().density 
}