Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's tools:layout in fragment xml file?

I started a new Android Application based on master/detail flow template using ADT Eclipse. This template creates two activities, a master fragment and a detail fragment in order to fit small and larger screens.

I noticed the activity_item_list.xml file has the tools:layout attribute:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/item_list"     android:name="com.example.fragmenttwopanel.ItemListFragment"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_marginLeft="16dp"     android:layout_marginRight="16dp"     tools:context=".ItemListActivity"     tools:layout="@android:layout/list_content" /> 

I tried to delete the attribute and the app runs in the same way but in the graphical layout tab of ADT, a message ask me for:

pick preview layout from the "Fragment Layout" context menu

What is its purpose? Is it just for preview in graphical layout?

like image 683
Josu Garcia de Albizu Avatar asked Oct 02 '13 11:10

Josu Garcia de Albizu


People also ask

Which layout is used in fragment?

Here are the important things to understand about fragments: A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library, fragments are supported back to all relevant Android versions.

What is Tools context in Android XML?

tools:context is such an attribute that is defined in any root view and declares which activity or fragment the layout is associated with. This declaration helps in enabling various features in the layout preview which demands the knowledge of the activity such as automatically choosing the necessary theme for preview.

What is layout in XML?

Android Layout is used to define the user interface that holds the UI controls or widgets that will appear on the screen of an android application or activity screen. Generally, every application is a combination of View and ViewGroup.


1 Answers

This is a namespace used by the IDE tools. This is not needed to run the application on a device (or emulator). On the other hand, if you leave them, Android will ignore them when the application is running on a device.

This is used by e.g. lint and graphical layout tab.

You can check how it's used by lint here: http://developer.android.com/tools/debugging/improving-w-lint.html in section Configuring lint checking in XML.

like image 69
Szymon Avatar answered Sep 19 '22 01:09

Szymon