Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

Request: set specific padding in one side (top/bottom/start/end) #211

@AndroidDeveloperLB

Description

@AndroidDeveloperLB

If you wish to set padding to a view, but only change one side of it, instead of all of them, you can't do it using the normal API, because it has only getter functions.

This is why I made this:

    //TODO use IntDef instead
    enum class ViewPadding {
        START_OR_LEFT, BOTTOM, END_OR_RIGHT, TOP
    }

fun View.setPaddingOrRelativePadding(paddingType: ViewHelper.ViewPadding, paddingValueToSetInPixels: Int) {
    when (paddingType) {
        ViewHelper.ViewPadding.BOTTOM -> ViewCompat.setPaddingRelative(this, ViewCompat.getPaddingStart(this), this.paddingTop, ViewCompat.getPaddingEnd(this), paddingValueToSetInPixels)
        ViewHelper.ViewPadding.END_OR_RIGHT -> ViewCompat.setPaddingRelative(this, ViewCompat.getPaddingStart(this), this.paddingTop, paddingValueToSetInPixels, this.paddingBottom)
        ViewHelper.ViewPadding.START_OR_LEFT -> ViewCompat.setPaddingRelative(this, paddingValueToSetInPixels, this.paddingTop, ViewCompat.getPaddingEnd(this), this.paddingBottom)
        ViewHelper.ViewPadding.TOP -> ViewCompat.setPaddingRelative(this, ViewCompat.getPaddingStart(this), paddingValueToSetInPixels, ViewCompat.getPaddingEnd(this), this.paddingBottom)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions