Android在xml文件中可使用include包含其他定义好的布局,

可以将多处用到的布局单独出来,然后用include包含进来

下面是一个简单的示例,两个xml文件:

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/main1"        layout="@layout/sublayout" />    <include        android:id="@+id/main2"        layout="@layout/sublayout" />    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text=" Start Another Activity " /></LinearLayout>


sublayout.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="wrap_content"    android:background="#505050"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="SubLayout" />    <Button        android:id="@+id/mybutton"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text=" A Button " /></LinearLayout>


更多相关文章

  1. Android工具之Hierarchy Viewer--分析应用程序UI布局
  2. Android 性能优化之布局优化 (二)
  3. Android常见布局简述
  4. Android:控件布局(线性布局)LinearLayout
  5. Android中Timer使用示例
  6. 布局(2、相对布局)
  7. android 设置布局为无标题样式

随机推荐

  1. Android多分辨率适配经验总结
  2. Python+PyQT5的子线程更新UI界面
  3. 第3章、第一个“Hello,world!”之Android
  4. AndroidStudio自定义注释模板笔记
  5. Android客户端实现图片轮播控件
  6. 微信授权APP第三方登陆(Android)
  7. Android之SqliteDatabase(MVP模式)实现用户
  8. Android(安卓)8.0通知权限的相关处理
  9. Android变声(SoundTouch)
  10. Android(安卓)多包名打包应用