Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>"

like image 641
loeschg Avatar asked Mar 25 '13 22:03

loeschg


People also ask

Can a fragment have its own view?

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.


1 Answers

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 :)

like image 79
Karl Avatar answered Oct 06 '22 00:10

Karl