如何使用ViewStub正确使用Kotlin Android扩展?
这些扩展是否有一个魔术来调用膨胀视图? 据我所知,我应该打破代码的和谐,并调用findViewById
意图是在某个时候膨胀layout_ongoingView
布局,并根据场景再次隐藏和可见
<ViewStub android:id="@+id/viewStubOngoing" android:layout_width="match_parent" android:layout_height="wrap_content" android:inflatedId="@+id/ongoingView" android:layout="@layout/layout_ongoingView" />
和代码
override fun hideOngoingPanel() { if (viewStubOngoing !is ViewStub) { findViewById(R.id.ongoingView).visibility = View.GONE } } override fun showOngoingPanel() { if (viewStubOngoing !is ViewStub) { findViewById(R.id.ongoingView).visibility = View.VISIBLE } else { viewStubOngoing.inflate() } }