How to display ViewStub preview in Android Studio?
Asked Answered
O

1

20

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.

Orcinol answered 25/9, 2017 at 13:54 Comment(3)
tools:visibility="visible"Transceiver
That doesn't work either. I will edit my question. I was trying out tools:visibility and copied the same into the question.Orcinol
Did you find the solution? I am wondering the same.Fawkes
I
18

Add this to the ViewStub:

tools:visibility="visible" 

and declare xmlns:tools="http://schemas.android.com/tools" in your layout.

Inner answered 13/11, 2019 at 17:26 Comment(1)
Awesome! It's not obvious but ViewStub invisible by defaultAnatropous

© 2022 - 2024 — McMap. All rights reserved.