论坛首页 移动开发技术论坛

android布局文件中的include

浏览 8018 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-02-27  

居然没有发现,在xml文件中可以使用include,我晕

一下为son.xml文件

 

<?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"
    >
	<Button 
		android:text="@+id/Button01" 
		android:id="@+id/Button01" 
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content">
	</Button>
		<Button 
		android:text="@+id/Button01" 
		android:id="@+id/Button02" 
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content">
	</Button>
</LinearLayout>

 

 接下来在main.xml文件中将其include进来,如下

<?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"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    <include layout="@layout/son"/>
</LinearLayout>
 运行效果不解释了。本来还在想,如果include2次,那么如何区分包含进来的控件的id呢,后来试了一下发现,不管include几次,其实都只相当于include了一次。
   发表时间:2011-02-27  
不错,第一次听说,见识了
0 请登录后投票
   发表时间:2011-02-27  
共享组件用的
0 请登录后投票
   发表时间:2011-02-28  
很实用的include
0 请登录后投票
   发表时间:2011-02-28  
大惊小怪,
0 请登录后投票
   发表时间:2011-02-28  
这个不是很多种布局类的东西都有相似的地方
0 请登录后投票
   发表时间:2011-03-30  
头一次使用了这种做法  布局文件的可重复使用性很强啊
0 请登录后投票
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics