I have a ViewStub like this -
<android.support.constraint.ConstraintLayout>
<ViewStub
android:id="@+id/photos"
android:layout="@layout/add_photos"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/details"
tools:visibility="visible" />
...
</android.support.constraint.ConstraintLayout>
But the ViewStub is not rendered in the layout preview and design tabs. Using <include/>
works though.
I am using Android Studio 3.0 Beta 6.
Is there a way to render preview when using ViewStub?
EDIT:
Looks like there is a feature request in google issue tracker https://issuetracker.google.com/issues/37090997. But no one has looked into it till now. I will still keep the question open if anyone has any workarounds.
When the ViewStub is inflated, it replaces itself in its parent view with the inflated layout resource. Its visibility will exist in the view hierarchy only when setVisibility(int) or inflate() is invoked. The inflated view is added to ViewStub's parent using the layout parameter.
A ViewStub is a zero-sized invisible View which is used to load "layout resource" at runtime. ViewStub is a zero dimension View, so you will not see anything on the layout pallete. To make parent resource visible, inflate() method is invoked. To make ViewStub visible or invisible, setVisibility(int) method is invoked.
Add this to the ViewStub:
tools:visibility="visible"
and declare xmlns:tools="http://schemas.android.com/tools" in your layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With