这样的解读在
[url]http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html[/url]
标记上,以备忘记
The [color=blue]@ [/color]symbol in the id strings of the [color=blue]ListView[/color] and [color=blue]TextView[/color] tags means that the XML parser should parse and expand the rest of the id string and use an ID resource.
The [color=blue]ListView[/color] and [color=blue]TextView[/color] can be thought as two alternative views, only one of which will be displayed at once. [color=blue]ListView[/color] will be used when there are notes to be shown, while the [color=blue]TextView [/color](which has a default value of "No Notes Yet!" defined as a string resource in [color=green]res/values/strings.xml[/color]) will be displayed if there aren't any notes to display.
The list and empty IDs are provided for us by the Android platform, so, we must prefix the id with [color=blue]android: [/color](e.g., @android:id/list).
The [color=blue]View [/color]with the empty id is used automatically when the [color=blue]ListAdapter [/color]has no data for the [color=blue]ListView[/color]. The [color=blue]ListAdapter [/color]knows to look for this name by default. Alternatively, you could change the default empty view by using [color=blue]setEmptyView[/color](View) on the [color=blue]ListView[/color].
More broadly, the [color=darkblue]android.R[/color] class is a set of predefined resources provided for you by the platform, while your project's [color=darkblue]R[/color] class is the set of resources your project has defined. Resources found in the [color=darkblue]android.R[/color] resource class can be used in the XML files by using the [color=blue]android: [/color]name space prefix (as we see here).
This is the View that will be used for each notes title row — it has only one text field in it.
In this case we create a new id called [color=blue]text1[/color]. The [b]+ [/b]after the [b]@[/b] in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining [color=blue]text1 [/color]on the fly and then using it.
[color=blue]layout_weight[/color] is used in LinearLayouts to assign "importance" to Views within the layout.[b] All Views have a default layout_weight of zero, meaning they take up only as much room on the screen as they need to be displayed.[/b] Assigning a value higher than zero will split up the rest of the available space in the parent View, according to the value of each View's [color=blue]layout_weight[/color] and its ratio to the overall [color=blue]layout_weight [/color]specified in the current layout for this and other View elements.
[url]http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html[/url]
标记上,以备忘记
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_notes"/>
</LinearLayout>
The [color=blue]@ [/color]symbol in the id strings of the [color=blue]ListView[/color] and [color=blue]TextView[/color] tags means that the XML parser should parse and expand the rest of the id string and use an ID resource.
The [color=blue]ListView[/color] and [color=blue]TextView[/color] can be thought as two alternative views, only one of which will be displayed at once. [color=blue]ListView[/color] will be used when there are notes to be shown, while the [color=blue]TextView [/color](which has a default value of "No Notes Yet!" defined as a string resource in [color=green]res/values/strings.xml[/color]) will be displayed if there aren't any notes to display.
The list and empty IDs are provided for us by the Android platform, so, we must prefix the id with [color=blue]android: [/color](e.g., @android:id/list).
The [color=blue]View [/color]with the empty id is used automatically when the [color=blue]ListAdapter [/color]has no data for the [color=blue]ListView[/color]. The [color=blue]ListAdapter [/color]knows to look for this name by default. Alternatively, you could change the default empty view by using [color=blue]setEmptyView[/color](View) on the [color=blue]ListView[/color].
More broadly, the [color=darkblue]android.R[/color] class is a set of predefined resources provided for you by the platform, while your project's [color=darkblue]R[/color] class is the set of resources your project has defined. Resources found in the [color=darkblue]android.R[/color] resource class can be used in the XML files by using the [color=blue]android: [/color]name space prefix (as we see here).
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
This is the View that will be used for each notes title row — it has only one text field in it.
In this case we create a new id called [color=blue]text1[/color]. The [b]+ [/b]after the [b]@[/b] in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining [color=blue]text1 [/color]on the fly and then using it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title" />
<EditText android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/body" />
<EditText android:id="@+id/body" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" />
<Button android:id="@+id/confirm"
android:text="@string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
[color=blue]layout_weight[/color] is used in LinearLayouts to assign "importance" to Views within the layout.[b] All Views have a default layout_weight of zero, meaning they take up only as much room on the screen as they need to be displayed.[/b] Assigning a value higher than zero will split up the rest of the available space in the parent View, according to the value of each View's [color=blue]layout_weight[/color] and its ratio to the overall [color=blue]layout_weight [/color]specified in the current layout for this and other View elements.