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.
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>"
Fragments cannot live on their own--they must be hosted by an activity or another fragment. The fragment's view hierarchy becomes part of, or attaches to, the host's view hierarchy.
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 :)
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