|
|
@@ -6,7 +6,7 @@ import androidx.constraintlayout.widget.ConstraintSet
|
|
|
import androidx.transition.TransitionManager
|
|
|
|
|
|
@Suppress("unused")
|
|
|
-fun ConstraintLayout.modify(withAnim: Boolean = false): ConstraintModify.ConstraintBegin {
|
|
|
+fun ConstraintLayout.modifyBegin(withAnim: Boolean = false): ConstraintModify.ConstraintBegin {
|
|
|
val begin = ConstraintModify(this).begin
|
|
|
if (withAnim) {
|
|
|
TransitionManager.beginDelayedTransition(this)
|
|
|
@@ -60,15 +60,12 @@ class ConstraintModify(private val constraintLayout: ConstraintLayout) {
|
|
|
) {
|
|
|
|
|
|
/**
|
|
|
- * 清除关系<br></br>
|
|
|
- * 注意:这里不仅仅会清除关系,还会清除对应控件的宽高为 w:0,h:0
|
|
|
- * @param viewIds
|
|
|
+ * 清除关系,这里不仅仅会清除关系,还会清除对应控件的宽高为 w:0,h:0
|
|
|
+ * @param viewId 视图ID
|
|
|
* @return
|
|
|
*/
|
|
|
- fun clear(@IdRes vararg viewIds: Int): ConstraintBegin {
|
|
|
- for (viewId in viewIds) {
|
|
|
- applyConstraintSet.clear(viewId)
|
|
|
- }
|
|
|
+ fun clear(viewId: Int): ConstraintBegin {
|
|
|
+ applyConstraintSet.clear(viewId)
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
@@ -78,8 +75,8 @@ class ConstraintModify(private val constraintLayout: ConstraintLayout) {
|
|
|
* @param anchor 要解除的关系
|
|
|
* @return
|
|
|
*/
|
|
|
- fun clear(viewId: Int, anchor: Int): ConstraintBegin {
|
|
|
- applyConstraintSet.clear(viewId, anchor)
|
|
|
+ fun clear(viewId: Int, anchor: Anchor): ConstraintBegin {
|
|
|
+ applyConstraintSet.clear(viewId, anchor.toInt())
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
@@ -280,4 +277,22 @@ class ConstraintModify(private val constraintLayout: ConstraintLayout) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ enum class Anchor {
|
|
|
+ LEFT, RIGHT, TOP, BOTTOM, BASELINE, START, END, CIRCLE_REFERENCE;
|
|
|
+
|
|
|
+ fun toInt(): Int {
|
|
|
+ return when (this) {
|
|
|
+ LEFT -> ConstraintSet.LEFT
|
|
|
+ RIGHT -> ConstraintSet.RIGHT
|
|
|
+ TOP -> ConstraintSet.TOP
|
|
|
+ BOTTOM -> ConstraintSet.BOTTOM
|
|
|
+ BASELINE -> ConstraintSet.BASELINE
|
|
|
+ START -> ConstraintSet.START
|
|
|
+ END -> ConstraintSet.END
|
|
|
+ CIRCLE_REFERENCE -> ConstraintSet.CIRCLE_REFERENCE
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|