Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

android - Android布局文件中的“工具:上下文”是什么?(What's “tools:context” in Android layout files?)

Starting with a recent new version of ADT, I've noticed this new attribute on the layout XML files, for example:

(从最新的ADT版本开始,我注意到布局XML文件上的这个新属性,例如:)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" />

What is "tools:context" used for?

(什么是“工具:上下文”用于?)

How does it even know the exact path to the activity that is written there?

(它怎么知道写在那里的活动的确切路径?)

Does it look at the package of the app, inside the manifest?

(它是否在清单中查看应用程序的包?)

Is it limited to classes that extend Context or only activities?

(它仅限于扩展Context或仅扩展活动的类吗?)

Is it usable for ListView items etc.?

(它可用于ListView项目等吗?)

  ask by android developer translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is the activity the tools UI editor uses to render your layout preview.

(这是工具UI编辑器用于呈现布局预览的活动。)

It is documented here :

(它记录在这里 :)

This attribute declares which activity this layout is associated with by default.

(此属性声明默认情况下此布局与哪个活动相关联。)

This enables features in the editor or layout preview that require knowledge of the activity, such as what the layout theme should be in the preview and where to insert onClick handlers when you make those from a quickfix

(这使得编辑器或布局预览中的功能需要活动知识,例如布局主题在预览中应该是什么以及当您从quickfix中进行插入时插入onClick处理程序的位置)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...