illusionJJ
illusionJJ

Reputation: 419

What is the checkbox default size

checkbox has fixed size. I wonder checkbox default dip size. Or how can I get default dip size.

Upvotes: 1

Views: 817

Answers (1)

Linh
Linh

Reputation: 60923

You can override onWindowFocusChanged method and inside it you can calculate the CheckBox width/height programmatically

@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 
}

Upvotes: 1

Related Questions