Is there a way to preview a fragment being used in another view in IntelliJ IDEA 12?

loeschg picture loeschg · Mar 25, 2013 · Viewed 8k times · Source

I recently made the switch from Eclipse to IntelliJ IDEA 12. Is there a good way to preview a fragment being used in another xml layout file?

In Eclipse there's a way to specify which fragment I'm using which is pretty helpful.

enter image description here

Edit (clarification): What I'm referring to is the ability to view a Fragment being referenced in another xml layout. Say I'm creating a Profile screen (activity_profile.xml) and want to include a fragment (fragment_pic.xml) that contains a picture, name, etc. When I include the fragment in the activity_profile.xml, it doesn't display in the preview for the activity_profile layout. It just displays "<fragment>"

Answer

Karl picture Karl · Aug 13, 2013

You can do this in the XML:

<fragment
    android:name="com.yourpackage.yourapp.yourfragment"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    tools:layout="@layout/fragment_layout" 
</fragment>

The tools namespace is qualified by this in the top view, same as xmlns:android namespace qualifier:

xmlns:tools="http://schemas.android.com/tools"

I had this same issue as well after moving from Eclipse to the Android Studio Preview though thankfully Android Studio suggests you provide this in the XML when it checks your definitions, very handy :)