For example, I want to realize something like this.
What should I do?
//res/layouts/main.xml
<layout>
<data>
<variable
name = "editable"
type = "boolean" / >
</data>
<FrameLayout>
<include layout="@{editable?@layout/editform:@layout/show}"/><!--←This doesn't work, I want to make this happen -->
</FrameLayout>
</layout>
Instead of describing it in xml, get the parent view from the program and inflate it by conditional branching.
Wrap the include tag in the appropriate ViewGroup and switch the visibility of the ViewGroup.
//res/layouts/main.xml
<layout>
<data>
<variable
name = "editable"
type = "boolean" / >
</data>
<FrameLayout android:id="@+id/rootLayout">
<FrameLayout
android: id="@+id/editform_layout"
android:visibility="@{editable?View.VISIBLE:View.GONE}"
tools:visibility="View.VISIBLE">
<include layout="@layout/editform"/>
</FrameLayout>
<FrameLayout
android: id="@+id/show_layout"
android:visibility="@{editable?View.GONE:View.VISIBLE}"
tools:visibility="View.GONE">
<include layout="@layout/show}"/>
</FrameLayout>
</FrameLayout>
</layout>
When I tried it, if the parent Layout (rootLayout) was ConstraintLayout, it collapsed.LinearLayout or FrameLayout would have been fine.
© 2024 OneMinuteCode. All rights reserved.