<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TabActivity" />
中有一个标签tools.
删掉这个属性之后发现会出现一个提示:pick
preview layout from the "Fragment Layout" context menu
文档上说:
| One more thing: The "tools" namespace is special. The android packaging tool knows to ignore it, so none of those attributes will be packaged into the APK. We're using it for extra metadata in the layout. It's also where for example the attributes to suppress lint warnings are stored -- as tools:ignore. |
原来tools:layout仅仅是告诉编辑器,Fragment在程序预览的时候该显示成什么样,并不会对apk产生实际作用,是为开发者设计的。
一般来说被xmlns:tools="http://schemas.android.com/tools" 声明的tools作为前缀的属性都不会被编译进去。这个跟上面代码中tools:context是一样的。
本文介绍了Android XML布局文件中android:tools标签的作用。该标签用于提供预览时的上下文信息,例如在ViewPager布局中,通过tools:context指定预览时的Activity,但这些属性不会在编译后的apk中生效。删除该属性会导致预览提示缺失。
1907

被折叠的 条评论
为什么被折叠?



