`
xiaoliang330
  • 浏览: 114512 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

android之layout配置文件解读

 
阅读更多
这样的解读在
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 Preference解读

    首先,`AndroidManifest.xml`文件是每个Android应用的核心配置文件,它包含了应用程序的基本信息和组件声明。在与Preference相关的应用中,我们需要在这里声明PreferenceActivity或PreferenceFragment。例如,我们...

    android二维码扫描ZXingDemo

    在Android平台上,二维码扫描功能是常见的需求之一,用于读取包含各种信息的二维码。ZXing(Zebra Crossing)是一个开源项目,提供了强大的条形码和二维码处理库,支持多种编码格式,如QR码、CODE_128、EAN等。在本...

    星星评分条

    在XML布局文件中,我们可以看到具体的`RatingBar`配置。例如: ```xml &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:paddingLeft="10dip...

    android demo,MyAndroidFlip的源代码的实现。

    根据提供的文件名"MyAndroidFlip",我们可以推测这是整个项目的根目录,包含所有必要的源代码文件、资源文件、配置文件等。可能包含的文件结构如下: 1. `src/` - 源代码目录,分为`java/`和`res/`两个子目录。 - ...

    Android开发\深入浅出Android.pdf

    - **视觉化工具**:使用Android Studio的Layout Editor进行拖放式界面设计,直观调整控件大小和位置。 #### 4. 解读程序流程 - **活动(Activity)生命周期**:理解Activity的创建、启动、暂停、停止、恢复和销毁...

    Android 的应用程序结构分析:HelloActivity

    - **AndroidManifest.xml**:应用程序的配置文件,包含应用的基本信息如权限声明、组件声明等。 - **res/layout/hello_activity.xml**:布局文件,定义了用户界面的布局结构。 - **res/values/strings.xml**:资源...

    Android Layout UI 首页加载过渡动画,星期变化动画

    - `.classpath`和`.project`:这两个文件是Eclipse(或旧版本的Android Studio)的工作区配置文件,用于管理项目的构建路径和项目设置。 - `project.properties`:这是Android项目的基本配置文件,包含SDK版本信息...

    Android学习笔记(二)App工程文件分析

    - `AndroidManifest.xml`是应用的主要配置文件,它提供了应用的基本信息和权限声明。这里: - `package`属性定义了应用的包名。 - `versionCode`和`versionName`分别表示应用的版本号和版本名称。 - `minSdk...

    Android游戏SpaceBlaster源代码

    - `AndroidManifest.xml`:这是每个Android应用的核心配置文件,它定义了应用的组件(如活动、服务等),权限请求,以及应用的入口点。在这个游戏中,我们可能会看到关于主活动(MainActivity)和任何其他相关服务...

    Android 视频播放 例子 源代码

    以下是对这个Android视频播放例子源代码的详细解读。 首先,Android系统提供了一个强大的多媒体框架,其中包括VideoView和MediaPlayer类,这两个类是我们实现视频播放的核心。VideoView可以直接在布局中嵌入,用于...

    Android 学习资源打包

    - Android资源文件夹(res/layout)中存储布局文件,通过XML元素描述UI结构。 4. **Android组件**: - 活动(Activity):作为应用的交互入口,负责展示用户界面。 - 服务(Service):后台运行的组件,不与用户...

    android应用源码(精)同城打工源码.zip

    1. `AndroidManifest.xml`:这是每个Android应用的核心配置文件,定义了应用的组件(如Activity、Service等),权限需求和其他元数据。 2. `src/main/java/`: 包含应用的Java源代码,按照包结构组织。这里可能有主...

    深入浅出_Google_Android(PDF格式高清中文版)

    - **视觉化的界面开发工具**:利用Android Studio中的Layout Editor等工具,以拖拽的方式设计UI布局。 - **获取标识ID**:学习如何给视图元素分配唯一的ID,以便在代码中引用它们。 - **存取识别符号**:掌握如何...

    《Android应用开发》个人总结报告.pdf

    此外,通过反射机制,开发者能快速构建界面,配置文件则方便设置界面属性和样式。 Android界面显示基于View和ViewGroup系统,每个界面元素都是一个View或ViewGroup的实例,配合XML样式文件来构建。ListView是一种...

    200款优秀Android项目源码

    首先,Android项目的源码通常包含以下几个核心部分:`AndroidManifest.xml`是应用的配置文件,它定义了应用的基本属性、权限以及组件的声明;`java`目录下的源代码文件是应用的主要逻辑,包含了Activity、Service、...

    深入浅出Android——Android开发经典教材.pdf

    - **新增XML文件**:在项目的res/layout目录下添加新的XML布局文件,用于定义特定界面的布局结构。 - **解读程序流程**:理解Android应用的运行机制,包括Activity生命周期、事件处理机制等,这对于编写高质量的应用...

    疯狂android讲义源码11-19章

    - 文件系统:了解Android的文件操作,包括读写文件、创建目录等。 - SQLite数据库:创建数据库,执行SQL语句,学习ContentProvider进行数据共享。 4. **Chapter 14:Android网络编程** - HTTP通信:使用...

Global site tag (gtag.js) - Google Analytics