这样的解读在
http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html

标记上,以备忘记

<?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 @ symbol in the id strings of the ListView and TextView tags means that the XML parser should parse and expand the rest of the id string and use an ID resource.
The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource in res/values/strings.xml) 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 android: (e.g., @android:id/list).
The View with the empty id is used automatically when the ListAdapter has no data for the ListView. The ListAdapter knows to look for this name by default. Alternatively, you could change the default empty view by using setEmptyView(View) on the ListView.

More broadly, the android.R class is a set of predefined resources provided for you by the platform, while your project's R class is the set of resources your project has defined. Resources found in the android.R resource class can be used in the XML files by using the android: 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 text1. The + after the @ 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 text1 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>




layout_weight is used in LinearLayouts to assign "importance" to Views within the layout. 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. 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 layout_weight and its ratio to the overall layout_weight specified in the current layout for this and other View elements.

更多相关文章

  1. Android中显示,隐藏Status Bar和Navigation Bar,沉浸式体验
  2. Android(安卓)spannableStringBuilder用法整理
  3. 解读Android(安卓)LOG机制的实现:c/c++域使用LOG
  4. Google 收购 Android(安卓)十周年 全面解读Android现状
  5. 解读Android(安卓)LOG机制的实现
  6. 解读Android(安卓)LOG机制的实现
  7. Android震动代码解读
  8. 一步步教你用Android(安卓)Google Map
  9. 解读新一代岗位要求(一) ----------------Android开发工程师

随机推荐

  1. android调用shell命令及权限问题
  2. android之从Bmob获取数据显示在ListView
  3. Win7上Git安装及简单配置过程
  4. ContentProvider和Uri详解
  5. Android提供了5种方式存储数据:
  6. 动态修改Android参数信息的方法绕过改机
  7. Android(安卓)媒体库数据更新
  8. 定制Android的Home
  9. 安乐得
  10. android library projects cannot be lau