【发布时间】:2019-04-15 03:32:35
【问题描述】:
我想做一个从一个约束集到另一个约束集的Changebounds() 动画。
通常我通过创建两个约束集来做到这一点:
private val originalState = ConstraintSet().apply {
clone(context, R.layout.layout_meta_syntactic)
}
private val expandedState = ConstraintSet().apply {
clone(context, R.layout.layout_meta_syntactic)
// Change some constraints
connect(
R.id.button, ConstraintSet.END,
R.id.foo_text, ConstraintSet.START
)
}
然后来回设置动画:
TransitionManager.beginDelayedTransition(id_of_my_component_in_fragment, transition)
originalState.applyTo(id_of_my_component_in_fragment)
但现在我在要从中克隆的布局中遇到了<merge> 标签。合并布局是扩展 ConstraintLayout 的复合组件的基础。
复合成分:
class MyCompoundView : ConstraintLayout {
// Omissions
inflate(context, R.layout.layout_meta_syntactic, this)
膨胀:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/some_id"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
// Views
当尝试以编程方式将布局克隆到约束集时,我得到:
Caused by: android.view.InflateException: Binary XML file line #2: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
Caused by: android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
如何从这样的布局创建约束集?
【问题讨论】:
标签: android kotlin android-constraintlayout