This commit is contained in:
kunfei
2023-05-21 14:24:51 +08:00
parent c59d612125
commit 5074f072e8
2 changed files with 29 additions and 15 deletions
@@ -16,7 +16,6 @@ import android.view.animation.Animation
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.appcompat.widget.PopupMenu
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.view.isGone
import androidx.core.view.isVisible
import io.legado.app.R
@@ -523,13 +522,13 @@ class ReadMenu @JvmOverloads constructor(
private fun upBrightnessVwPos() {
if (AppConfig.brightnessVwPos) {
binding.root.modify()
.clear(R.id.ll_brightness, ConstraintSet.LEFT)
binding.root.modifyBegin()
.clear(R.id.ll_brightness, ConstraintModify.Anchor.LEFT)
.rightToRightOf(R.id.ll_brightness, R.id.vw_menu_root)
.commit()
} else {
binding.root.modify()
.clear(R.id.ll_brightness, ConstraintSet.RIGHT)
binding.root.modifyBegin()
.clear(R.id.ll_brightness, ConstraintModify.Anchor.RIGHT)
.leftToLeftOf(R.id.ll_brightness, R.id.vw_menu_root)
.commit()
}
@@ -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
}
}
}
}