在main.xml中包含aaa.xml,bbb.xml
aaa.xml
<?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"
android:orientation="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="a" />
</LinearLayout>
bbb.xml
<?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"
android:orientation="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="a" />
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:id="@+id/a"
layout="@layout/aaa" />
<include
android:id="@+id/b"
layout="@layout/bbb" />
</LinearLayout>
效果图
获取组件
public class LayoutTestActivity extends Activity {
private LinearLayout l1, l2;
private TextView tv1, tv2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
l1 = (LinearLayout) findViewById(R.id.a);
tv1 = (TextView) l1.findViewById(R.id.tv);
l2 = (LinearLayout) findViewById(R.id.b);
tv2 = (TextView) l2.findViewById(R.id.tv);
tv1.setText("aaaaaaaaaaaaaaaaaaaaaaaa");
tv2.setText("bbbbbbbbbbbbbbbbbbbbbbbb");
}
}
效果图
- 大小: 2.6 KB
- 大小: 5.7 KB
- 大小: 3.5 KB
分享到:
相关推荐
Android UI优化之include标签使用,主要介绍include使用方法及注意事项。
android include merge标签
Android中include和merge标签的基本使用方法
android中include和merge标记的区别和使用
主要介绍了Android编程之include文件的使用方法,实例分析了Android使用include引入文件的技巧,有助于增加代码的重用性,提高程序设计效率,需要的朋友可以参考下
该资源主要是参考博客[Android] 使用Include布局+Fragment滑动切换屏幕的文章 主要讲述使用Include布局,同时像微信一样实现动态切换屏幕的效果.免费资源希望对大家有所帮助.
关于xml布局中标签<include />的使用的一个Demo
Android中Include的使用
我们是给这些个Activity布局文件都统一加上一样的布局代码,但是维护起来很麻烦,修改不方便,有没有一种类似于编程语言的include语法呢?答案是有的,但是sdk的demo并没有说出使用方法,但这并不说明不好使用,其实...
为android平台编译的ffmpeg so库 和 对用的 include文件,方便直接在android studio中进行ndk开发,来源于博客https://blog.csdn.net/zhangpengzp/article/details/82289224 使用so的方法: ...
主要介绍了Android中使用include标签和merge标签重复使用布局,文中讲解了创建可复用布局的例子以及include标签和merge标签使用例子,需要的朋友可以参考下
NULL 博文链接:https://2528.iteye.com/blog/1138475
在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include> 标签来重用layout...
主要介绍了android使用include调用内部组件的方法,涉及Android组件调用的相关技巧,需要的朋友可以参考下
android ffmpeg include 开发ffmpeg需要的头文件
主要介绍了Android开发中include控件用法,结合实例形式分析了Android界面布局中include控件的使用技巧,需要的朋友可以参考下