@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (changed) { widthTableRow = mTableLayout.getMeasuredWidth() - mTableLayout.getPaddingLeft() - mTableLayout.getPaddingRight(); widthItem = widthTableRow / buttonList.size(); heightItem = mTableLayout.getMeasuredHeight() - mTableLayout.getPaddingTop() - mTableLayout.getPaddingBottom(); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(widthItem, heightItem); mToggleSelector.setLayoutParams(lp); setSelected(currentState); } }