这样的解读在
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.
分享到:
相关推荐
为什么有时候像android:layout_marginBottom等变量的赋值为负数? 例如如下代码: android:orientation="vertical" android:id="@id/Widget_2X4_frame" android:layout_width="fill_parent" android:...
主要是针对android初学者对于android的layout布局不是很清楚的人
android的layout布局种类
android_layout属性大全,包括layou的各种属性的汉语意思.方便查找对应个属性
Android FloatLayout的简单使用
android提供的五种布局有时候不能满足实际项目的需要,所以需要自定义布局。这是一个自定义Layout布局
android的layout布局种类.pdf
android 布局Layout 各种布局使用到的一些重要的属性设置
android layout id converter
你了解Android Layout中的属性没?你清楚在layout中用什么属性没,不用担心,这里告诉你啦
android根据layout文件生成activity及自动注册 Demo 未完善,只是自己用来看的
android 自动换行 layout 适合做标签 使用简单 快速集成
包含所有的Android Layout的样式布局和属性讲解
介绍Android五中布局的一个示例代码.
适合初学者对android layout 的了解
点对点 Android_Layout_之_RelativeLayout_代码实现相对布局 使用
我们对Android应用程序运行原理及布局文件可谓有了比较深刻的认识和理解,并且用“Hello World!”程序来实践证明了。在继续深入Android开发之旅之前,有必要解决前两篇中没有介绍的遗留问题:View的几种布局显示...
android layout 设计软件 外带软件,解压后,直接双击运行就可以直接操作
android:layout_gravity 属性详细解读