Java Code Examples for android.support.v4.view.MarginLayoutParamsCompat#setMarginEnd()

The following examples show how to use android.support.v4.view.MarginLayoutParamsCompat#setMarginEnd() . 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: AbsQuizView.java    From android-topeka with Apache License 2.0 6 votes vote down vote up
private void addFloatingActionButton() {
    final int fabSize = getResources().getDimensionPixelSize(R.dimen.size_fab);
    int bottomOfQuestionView = findViewById(R.id.question_view).getBottom();
    final LayoutParams fabLayoutParams = new LayoutParams(fabSize, fabSize,
            Gravity.END | Gravity.TOP);
    final int halfAFab = fabSize / 2;
    fabLayoutParams.setMargins(0, // left
            bottomOfQuestionView - halfAFab, //top
            0, // right
            mSpacingDouble); // bottom
    MarginLayoutParamsCompat.setMarginEnd(fabLayoutParams, mSpacingDouble);
    if (ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
        // Account for the fab's emulated shadow.
        fabLayoutParams.topMargin -= (mSubmitAnswer.getPaddingTop() / 2);
    }
    addView(mSubmitAnswer, fabLayoutParams);
}
 
Example 2
Source File: PercentLayoutHelper.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void restoreMarginLayoutParams(MarginLayoutParams params) {
    restoreLayoutParams(params);
    params.leftMargin = this.mPreservedParams.leftMargin;
    params.topMargin = this.mPreservedParams.topMargin;
    params.rightMargin = this.mPreservedParams.rightMargin;
    params.bottomMargin = this.mPreservedParams.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(params, MarginLayoutParamsCompat.getMarginStart(this.mPreservedParams));
    MarginLayoutParamsCompat.setMarginEnd(params, MarginLayoutParamsCompat.getMarginEnd(this.mPreservedParams));
}
 
Example 3
Source File: PercentLayoutHelper.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
/**
 * Restores the original dimensions and margins after they were changed for percentage based
 * values. You should call this method only if you previously called
 * {@link PercentLayoutHelper.PercentLayoutInfo#fillMarginLayoutParams(View, ViewGroup.MarginLayoutParams, int, int)}.
 */
public void restoreMarginLayoutParams(ViewGroup.MarginLayoutParams params) {
    restoreLayoutParams(params);
    params.leftMargin = mPreservedParams.leftMargin;
    params.topMargin = mPreservedParams.topMargin;
    params.rightMargin = mPreservedParams.rightMargin;
    params.bottomMargin = mPreservedParams.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(params,
            MarginLayoutParamsCompat.getMarginStart(mPreservedParams));
    MarginLayoutParamsCompat.setMarginEnd(params,
            MarginLayoutParamsCompat.getMarginEnd(mPreservedParams));
}
 
Example 4
Source File: PercentLayoutHelper.java    From android-percent-support-extend with Apache License 2.0 5 votes vote down vote up
/**
 * Restores original dimensions and margins after they were changed for percentage based
 * values. Calling this method only makes sense if you previously called
 * {@link PercentLayoutHelper.PercentLayoutInfo#fillMarginLayoutParams}.
 */
public void restoreMarginLayoutParams(ViewGroup.MarginLayoutParams params)
{
    restoreLayoutParams(params);
    params.leftMargin = mPreservedParams.leftMargin;
    params.topMargin = mPreservedParams.topMargin;
    params.rightMargin = mPreservedParams.rightMargin;
    params.bottomMargin = mPreservedParams.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(params,
            MarginLayoutParamsCompat.getMarginStart(mPreservedParams));
    MarginLayoutParamsCompat.setMarginEnd(params,
            MarginLayoutParamsCompat.getMarginEnd(mPreservedParams));
}
 
Example 5
Source File: PercentLayoutHelper.java    From FimiX8-RE with MIT License 4 votes vote down vote up
public void fillMarginLayoutParams(MarginLayoutParams params, int widthHint, int heightHint) {
    int base;
    fillLayoutParams(params, widthHint, heightHint);
    this.mPreservedParams.leftMargin = params.leftMargin;
    this.mPreservedParams.topMargin = params.topMargin;
    this.mPreservedParams.rightMargin = params.rightMargin;
    this.mPreservedParams.bottomMargin = params.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(this.mPreservedParams, MarginLayoutParamsCompat.getMarginStart(params));
    MarginLayoutParamsCompat.setMarginEnd(this.mPreservedParams, MarginLayoutParamsCompat.getMarginEnd(params));
    if (this.leftMarginPercent != null) {
        params.leftMargin = (int) (((float) (this.leftMarginPercent.isBaseWidth ? widthHint : heightHint)) * this.leftMarginPercent.percent);
    }
    if (this.topMarginPercent != null) {
        if (this.topMarginPercent.isBaseWidth) {
            base = widthHint;
        } else {
            base = heightHint;
        }
        params.topMargin = (int) (((float) base) * this.topMarginPercent.percent);
    }
    if (this.rightMarginPercent != null) {
        if (this.rightMarginPercent.isBaseWidth) {
            base = widthHint;
        } else {
            base = heightHint;
        }
        params.rightMargin = (int) (((float) base) * this.rightMarginPercent.percent);
    }
    if (this.bottomMarginPercent != null) {
        if (this.bottomMarginPercent.isBaseWidth) {
            base = widthHint;
        } else {
            base = heightHint;
        }
        params.bottomMargin = (int) (((float) base) * this.bottomMarginPercent.percent);
    }
    if (this.startMarginPercent != null) {
        if (this.startMarginPercent.isBaseWidth) {
            base = widthHint;
        } else {
            base = heightHint;
        }
        MarginLayoutParamsCompat.setMarginStart(params, (int) (((float) base) * this.startMarginPercent.percent));
    }
    if (this.endMarginPercent != null) {
        if (this.endMarginPercent.isBaseWidth) {
            base = widthHint;
        } else {
            base = heightHint;
        }
        MarginLayoutParamsCompat.setMarginEnd(params, (int) (((float) base) * this.endMarginPercent.percent));
    }
    if (Log.isLoggable(PercentLayoutHelper.TAG, 3)) {
        Log.d(PercentLayoutHelper.TAG, "after fillMarginLayoutParams: (" + params.width + ", " + params.height + ")");
    }
}
 
Example 6
Source File: PercentLayoutHelper.java    From JD-Test with Apache License 2.0 4 votes vote down vote up
/**
 * Fills the margin fields of the passed {@link ViewGroup.MarginLayoutParams} object based
 * on currently set percentage values and the current layout direction of the passed
 * {@link View}.
 */
public void fillMarginLayoutParams(View view, ViewGroup.MarginLayoutParams params,
                                   int widthHint, int heightHint) {
    fillLayoutParams(params, widthHint, heightHint);

    // Preserve the original margins, so we can restore them after the measure step.
    mPreservedParams.leftMargin = params.leftMargin;
    mPreservedParams.topMargin = params.topMargin;
    mPreservedParams.rightMargin = params.rightMargin;
    mPreservedParams.bottomMargin = params.bottomMargin;
    MarginLayoutParamsCompat.setMarginStart(mPreservedParams,
            MarginLayoutParamsCompat.getMarginStart(params));
    MarginLayoutParamsCompat.setMarginEnd(mPreservedParams,
            MarginLayoutParamsCompat.getMarginEnd(params));
    int screenWidth = ScreenUtil.getScreenWidth(view.getContext());

    if (leftMarginPercentX >= 0) {
        params.leftMargin = Math.round(widthHint * leftMarginPercentX);
    }
    else if (leftMarginPercentY >= 0) {
        params.leftMargin = Math.round(heightHint * leftMarginPercentY);
    }
    else if (leftMarginPercentScreenX >= 0) {
        params.leftMargin = Math.round(screenWidth * leftMarginPercentScreenX);
    }


    if (topMarginPercentX >= 0) {
        params.topMargin = Math.round(widthHint * topMarginPercentX);
    }
    else if (topMarginPercentY >= 0) {
        params.topMargin = Math.round(heightHint * topMarginPercentY);
    }
    else if (topMarginPercentScreenX >= 0) {
        params.topMargin = Math.round(screenWidth * topMarginPercentScreenX);
    }


    if (rightMarginPercentX >= 0) {
        params.rightMargin = Math.round(widthHint * rightMarginPercentX);
    }
    else if (rightMarginPercentY >= 0) {
        params.rightMargin = Math.round(heightHint * rightMarginPercentY);
    }
    else if (rightMarginPercentScreenX >= 0) {
        params.rightMargin = Math.round(screenWidth * rightMarginPercentScreenX);
    }


    if (bottomMarginPercentX >= 0) {
        params.bottomMargin = Math.round(widthHint * bottomMarginPercentX);
    }
    else if(bottomMarginPercentY >= 0){
        params.bottomMargin = Math.round(heightHint * bottomMarginPercentY);
    }
    else if(bottomMarginPercentScreenX >= 0){
        params.bottomMargin = Math.round(screenWidth * bottomMarginPercentScreenX);
    }


    boolean shouldResolveLayoutDirection = false;
    if (startMarginPercent >= 0) {
        MarginLayoutParamsCompat.setMarginStart(params,
                Math.round(widthHint * startMarginPercent));
        shouldResolveLayoutDirection = true;
    }
    if (endMarginPercent >= 0) {
        MarginLayoutParamsCompat.setMarginEnd(params,
                Math.round(widthHint * endMarginPercent));
        shouldResolveLayoutDirection = true;
    }
    if (shouldResolveLayoutDirection && (view != null)) {
        // Force the resolve pass so that start / end margins are propagated to the
        // matching left / right fields
        MarginLayoutParamsCompat.resolveLayoutDirection(params,
                ViewCompat.getLayoutDirection(view));
    }
    if (DEBUG) {
        Log.d(TAG, "after fillMarginLayoutParams: (" + params.width + ", " + params.height
                + ")");
    }
}
 
Example 7
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 4 votes vote down vote up
private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.FloatingSearchView, defStyleAttr, defStyleRes);

    // Search bar width
    View suggestionsContainer = findViewById(R.id.fsv_suggestions_container);
    int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth,
            mSearchContainer.getLayoutParams().width);
    mSearchContainer.getLayoutParams().width = searchBarWidth;
    suggestionsContainer.getLayoutParams().width = searchBarWidth;

    // Divider
    mDivider.setBackgroundDrawable(a.getDrawable(R.styleable.FloatingSearchView_android_divider));
    int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1);

    MarginLayoutParams dividerLP = (MarginLayoutParams) mDivider.getLayoutParams();

    if(mDivider.getBackground() != null && dividerHeight != -1)
        dividerLP.height = dividerHeight;

    float maxShadowSize = mSearchBackground.getMaxShadowSize();
    float cornerRadius = mSearchBackground.getCornerRadius();
    int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(
            maxShadowSize, cornerRadius, false) + .5f);

    dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin);
    mDivider.setLayoutParams(dividerLP);

    // Content inset
    MarginLayoutParams searchParams = (MarginLayoutParams) mSearchInput.getLayoutParams();

    int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart,
            MarginLayoutParamsCompat.getMarginStart(searchParams));
    int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd,
            MarginLayoutParamsCompat.getMarginEnd(searchParams));

    MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart);
    MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd);

    // anything else
    setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo));
    setContentBackgroundColor(a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR));
    setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius, ViewUtils.dpToPx(DEFAULT_RADIUS)));
    inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0));
    setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0));
    setHint(a.getString(R.styleable.FloatingSearchView_android_hint));
    setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon));

    a.recycle();
}
 
Example 8
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 4 votes vote down vote up
private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs,
            R.styleable.FloatingSearchView, defStyleAttr, defStyleRes);

    // Search bar width
    View suggestionsContainer = findViewById(R.id.fsv_suggestions_container);
    int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth,
            mSearchContainer.getLayoutParams().width);
    mSearchContainer.getLayoutParams().width = searchBarWidth;
    suggestionsContainer.getLayoutParams().width = searchBarWidth;

    // Divider
    mDivider.setBackgroundDrawable(a.getDrawable(R.styleable.FloatingSearchView_android_divider));
    int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1);

    MarginLayoutParams dividerLP = (MarginLayoutParams) mDivider.getLayoutParams();

    if(mDivider.getBackground() != null && dividerHeight != -1)
        dividerLP.height = dividerHeight;

    float maxShadowSize = mSearchBackground.getMaxShadowSize();
    float cornerRadius = mSearchBackground.getCornerRadius();
    int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(
            maxShadowSize, cornerRadius, false) + .5f);

    dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin);
    mDivider.setLayoutParams(dividerLP);

    // Content inset
    MarginLayoutParams searchParams = (MarginLayoutParams) mSearchInput.getLayoutParams();

    int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart,
            MarginLayoutParamsCompat.getMarginStart(searchParams));
    int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd,
            MarginLayoutParamsCompat.getMarginEnd(searchParams));

    MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart);
    MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd);

    // anything else
    setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo));
    setContentBackgroundColor(a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR));
    setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius, ViewUtils.dpToPx(DEFAULT_RADIUS)));
    inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0));
    setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0));
    setHint(a.getString(R.styleable.FloatingSearchView_android_hint));
    setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon));

    a.recycle();
}