Java Code Examples for android.widget.CompoundButton#getLayoutParams()

The following examples show how to use android.widget.CompoundButton#getLayoutParams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlexboxHelper.java    From Collection-Android with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: ToggleGroup.java    From ToggleButtons with MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: ToggleGroup.java    From ToggleButtons with MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 4
Source File: ToggleGroup.java    From ToggleButtons with MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 5
Source File: ToggleGroup.java    From ToggleButtons with MIT License 5 votes vote down vote up
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);
        }
    }
}