-
-
Save wangyung/cd3d6a85bae2b3cfd0b153bbf1867ee5 to your computer and use it in GitHub Desktop.
Anko ConstraintLayout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.content.Context | |
import android.support.constraint.ConstraintLayout | |
import android.util.AttributeSet | |
import android.view.View | |
import android.view.ViewGroup | |
import android.view.ViewManager | |
import org.jetbrains.anko.AnkoViewDslMarker | |
import org.jetbrains.anko.custom.ankoView | |
open class _ConstraintLayout(ctx: Context) : ConstraintLayout(ctx) { | |
inline fun <T : View> T.lparams( | |
c: Context?, | |
attrs: AttributeSet?, | |
init: ConstraintLayout.LayoutParams.() -> Unit | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(c!!, attrs!!) | |
layoutParams.init() | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
c: Context?, | |
attrs: AttributeSet? | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(c!!, attrs!!) | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
width: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT, | |
height: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT, | |
init: ConstraintLayout.LayoutParams.() -> Unit | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(width, height) | |
layoutParams.init() | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
width: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT, | |
height: Int = android.view.ViewGroup.LayoutParams.WRAP_CONTENT | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(width, height) | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ViewGroup.LayoutParams?, | |
init: ConstraintLayout.LayoutParams.() -> Unit | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
layoutParams.init() | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ViewGroup.LayoutParams? | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ViewGroup.MarginLayoutParams?, | |
init: ConstraintLayout.LayoutParams.() -> Unit | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
layoutParams.init() | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ViewGroup.MarginLayoutParams? | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ConstraintLayout.LayoutParams?, | |
init: ConstraintLayout.LayoutParams.() -> Unit | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
layoutParams.init() | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
inline fun <T : View> T.lparams( | |
source: ConstraintLayout.LayoutParams? | |
): T { | |
val layoutParams = ConstraintLayout.LayoutParams(source!!) | |
layoutParams.validate() | |
[email protected] = layoutParams | |
return this | |
} | |
} | |
inline fun ViewManager.constraintLayout(): _ConstraintLayout = constraintLayout {} | |
inline fun ViewManager.constraintLayout(init: (@AnkoViewDslMarker _ConstraintLayout).() -> Unit): _ConstraintLayout { | |
return ankoView(::_ConstraintLayout, theme = 0) { init() } | |
} | |
inline fun ViewManager.themedConstraintLayout(theme: Int = 0): _ConstraintLayout = themedConstraintLayout(theme) {} | |
inline fun ViewManager.themedConstraintLayout(theme: Int = 0, init: (@AnkoViewDslMarker _ConstraintLayout).() -> Unit): _ConstraintLayout { | |
return ankoView(::_ConstraintLayout, theme) { init() } | |
} | |
inline fun Context.constraintLayout(): _ConstraintLayout = constraintLayout {} | |
inline fun Context.constraintLayout(init: (@AnkoViewDslMarker _ConstraintLayout).() -> Unit): _ConstraintLayout { | |
return ankoView(::_ConstraintLayout, theme = 0) { init() } | |
} | |
inline fun Context.themedConstraintLayout(theme: Int = 0): _ConstraintLayout = themedConstraintLayout(theme) {} | |
inline fun Context.themedConstraintLayout(theme: Int = 0, init: (@AnkoViewDslMarker _ConstraintLayout).() -> Unit): _ConstraintLayout { | |
return ankoView(::_ConstraintLayout, theme) { init() } | |
} | |
inline fun Activity.constraintLayout(): _ConstraintLayout = constraintLayout {} | |
inline fun Activity.constraintLayout(init: (@AnkoViewDslMarker _ConstraintLayout).() -> Unit): _ConstraintLayout { | |
return ankoView(::_ConstraintLayout, theme = 0) { init() } | |
} | |
val parentId: Int = ConstraintLayout.LayoutParams.PARENT_ID | |
val matchConstraint: Int = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT | |
val matchConstraintWrap: Int = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_WRAP | |
val matchConstraintSpread: Int = ConstraintLayout.LayoutParams.MATCH_CONSTRAINT_SPREAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment