下面列出了android.widget.CompoundButton#getLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Compound buttons (ex. {{@link android.widget.CheckBox}}, {@link android.widget.ToggleButton})
* have a button drawable with minimum height and width specified for them.
* To align the behavior with CSS Flexbox we want to respect these minimum measurement to avoid
* these drawables from being cut off during calculation. When the compound button has a minimum
* width or height already specified we will not make any change since we assume those were
* voluntarily set by the user.
*
* @param compoundButton the compound button that need to be evaluated
*/
private void evaluateMinimumSizeForCompoundButton(CompoundButton compoundButton) {
FlexItem flexItem = (FlexItem) compoundButton.getLayoutParams();
int minWidth = flexItem.getMinWidth();
int minHeight = flexItem.getMinHeight();
Drawable drawable = CompoundButtonCompat.getButtonDrawable(compoundButton);
int drawableMinWidth = drawable == null ? 0 : drawable.getMinimumWidth();
int drawableMinHeight = drawable == null ? 0 : drawable.getMinimumHeight();
flexItem.setMinWidth(minWidth == NOT_SET ? drawableMinWidth : minWidth);
flexItem.setMinHeight(minHeight == NOT_SET ? drawableMinHeight : minHeight);
}
void drawDividersVertical(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final CompoundButton child = (CompoundButton) getChildAt(i);
if (hasDividerBeforeChildAt(i)) {
final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
final int top = child.getTop() - lp.topMargin - mDividerHeight;
drawHorizontalDivider(canvas, top);
}
}
}
void drawDividersHorizontal(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final CompoundButton child = (CompoundButton) getChildAt(i);
if (hasDividerBeforeChildAt(i)) {
final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - lp.leftMargin - mDividerWidth;
drawVerticalDivider(canvas, left);
}
}
}
void drawDividersVertical(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final CompoundButton child = (CompoundButton) getChildAt(i);
if (hasDividerBeforeChildAt(i)) {
final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
final int top = child.getTop() - lp.topMargin - mDividerHeight;
drawHorizontalDivider(canvas, top);
}
}
}
void drawDividersHorizontal(Canvas canvas) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final CompoundButton child = (CompoundButton) getChildAt(i);
if (hasDividerBeforeChildAt(i)) {
final LinearLayoutCompat.LayoutParams lp = (LinearLayoutCompat.LayoutParams) child.getLayoutParams();
final int left = child.getLeft() - lp.leftMargin - mDividerWidth;
drawVerticalDivider(canvas, left);
}
}
}