我尝试了三个多小时才能使ViewStub正常运行。这是我第一次处理它,却不知道如何使用它。
我检查了许多教程和论坛帖子,但所有教程和论坛帖子都仅显示“可见性消失”和“可见性”。但是,我正在寻找一些根据用户选择的选项切换部分布局(这是一种表单)的解决方案。
<ViewStub
android:id="@+id/dialog_view_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/app_space"
android:layout_marginEnd="@dimen/app_space_half"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/option_text_note"
app:layout_constraintBottom_toTopOf="@+id/button_add"
android:layout="@layout/layout_dialog_text_input"/>
ViewStub viewStub = view.findViewById( R.id.dialog_view_stub );
viewStub.inflate();