`
iaiai
  • 浏览: 2211187 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

android tools:context=”.MainActivity”与xmlns:tools名字空间

 
阅读更多
ADT20.0,新建Android Application Project:

默认的布局文件内容变化了:
LinearLayout变成了RelativeLayout:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
android:textSize="18sp"
tools:context=".MainActivity" />

还多了个新的namespace和相应的属性,这个属性的作用是什么呢?解释如下:

请各自选择相应语种,对号入座,O(∩_∩)O~

English Original Explaination:
引用
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:context="activity name"这一句不会被打包进APK。只是ADT的Layout Editor在你当前的Layout文件里面设置对应的渲染上下文,说明你当前的Layout所在的渲染上下文是activity name对应的那个activity,如果这个activity在manifest文件中设置了Theme,那么ADT的Layout Editor会根据这个Theme来渲染你当前的Layout。就是说如果你设置的MainActivity设置了一个Theme.Light(其他的也可以),那么你在可视化布局管理器里面看到的背景阿控件阿什么的就应该是Theme.Light的样子。仅用于给你看所见即所得的效果而已。
分享到:
评论

相关推荐

    安卓音乐播放器

    &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app=... tools:context=".MainActivity"&gt;

    Java就应该这样学

    Java就应该这样学PDF高清版.pdf ... tools:context=".MainActivity" &gt; android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /&gt; &lt;/RelativeLayout&gt;

    自定义弹幕View,简单实现Android弹幕,一类修改,最简单.zip

    自定义弹幕View,简单实现Android弹幕,一类修改,最简单BarrageView- 效果图如何使用?/如何使用?-1直接把BarrageView这个类放到项目里面2:布局文件&lt;RelativeLayout xmlns:android=......

    本地图片上传

    tools:context=".MainActivity" &gt; android:id="@+id/ivPic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_...

    高仿新版58加载动画Android-shapeLoadingView.zip

     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;  &lt;com.mingle.widget.LoadingView  android:id="@ id/loadView"  android:layout_width="fill_parent"  android:...

    WeChatSample

    tools:context="com.example.wechat.wechat.MainActivity" android:orientation="vertical"&gt; &lt;include layout="@layout/top_layout" /&gt; &lt;android.support.v4.view.ViewPager android:layout_weight="1" ...

    Android实现侧滑菜单DrawerLayout

    tools:context=".MainActivity"&gt; &lt;androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;androidx.appcompat.widget.Toolbar ...

    WebViewDownloadTest.zip

    tools:context="com.example.y.webviewdownloadtest.MainActivity"&gt; android:id="@+id/ll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"&gt; ...

    android百度地图

    tools:context="${relativePackage}.${activityClass}" &gt; &lt;com.baidu.mapapi.map.MapView android:id="@+id/bmapview" android:layout_width="match_parent" android:layout_height="match_parent" ...

    Android版得HelloWorld

    tools:context=".MainActivity" android:orientation="vertical"&gt; android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /...

    九宫格牌翻转游戏demo

    tools:context=".EX04_06" &gt; android:id="@+id/LayoutButtons3" android:layout_marginTop="5dp" android:layout_width="230dp" android:layout_height="95dp" android:layout_centerHorizontal="true" ...

    Android实现图片自动轮换

    tools:context=".MainActivity"&gt; android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; android:id="@+id/btn_choose_picture" android:layout_...

    Android命令行开发环境搭建和HelloWorld Project

    tools:context=".MainActivity"&gt; android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_...

    Android 一个简单的Helloworld程序

    tools:context=".MainActivity"&gt; android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, World!" android:textSize="24sp" /&gt; ``...

    应用表格布局管理器实现喜马拉雅的用户登录页面

    tools:context=".MainActivity"&gt; ``` 在上面的代码中,我们设置了表格布局管理器的宽度和高度为 match_parent,以便它可以填充整个屏幕。我们还设置了 stretchColumns 属性为 0,3,表示第 1 列和第 4 列将被拉伸以...

    实验一android开发环境搭建与hello.docx

    Android 开发环境搭建与 Hello World 应用开发 Android 开发环境搭建是 Android 应用开发的第一步,包括安装 Java JDK、下载 Eclipse、安装 ADT(Android Development Tools)、安装 Android SDK 等步骤。通过搭建...

    Android中用xml配置旋转动画的代码清单.pdf

    tools:context=".MainActivity" android:background="#fff"&gt; android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY" android:...

    listview的使用实例

    tools:context=".MainActivity"&gt; android:id="@+id/lv_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_...

Global site tag (gtag.js) - Google Analytics