iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >解析android中include标签的使用
  • 120
分享到

解析android中include标签的使用

includeAndroid 2022-06-06 10:06:34 120人浏览 薄情痞子
摘要

在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过

在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include /> 标签来重用layout代码。
app_title.xml:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout Android:id="@+id/titleLayout" android:layout_width="fill_parent" android:layout_height="wrap_content"
   android:background="@drawable/bt" xmlns:android="Http://schemas.android.com/apk/res/android">
  <TextView android:text="@string/login" android:id="@+id/title" android:textSize="20px" android:textColor="@color/white"
   android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content"/>  
  <Button android:text="返回" android:id="@+id/refresh" android:layout_width="wrap_content" android:layout_height="wrap_content"
   android:layout_alignParentRight="true" android:focusable="false" android:textColor="@color/white"
   android:background="@drawable/okbutton" android:layout_marginRight="3px"/>
</RelativeLayout>

app_tradelogin.xml:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- android:layout_below与 android:layout_above 是必须设置的,否则界面不规则,不设置android:layout_above本界面没有滑动效果-->
<ScrollView android:layout_below="@+id/titleLayout" android:layout_above="@+id/appbottom" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:layout_centerInParent="true" xmlns:android="http://schemas.android.com/apk/res/android">
 <LinearLayout android:id="@+id/theWholeLinearLayout" android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:paddingLeft="10px" android:paddingTop="6px" android:paddingRight="10px" >
  <LinearLayout android:id="@+id/linearLayoutLeft" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
   <TableLayout android:id="@+id/widget43" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" android:stretchColumns="1">
    <TableRow >
    <!--  引用定义好的TextView样式,如果这里的属性和样式里定义的属性重复,则这里会替换样式里定义的属性-->
     <TextView android:id="@+id/traderName" android:text="@string/traderName" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <Spinner android:id="@+id/traderNameS" android:layout_width="fill_parent" android:layout_height="wrap_content">
     </Spinner>
    </TableRow>
    <TableRow>
     <TextView android:id="@+id/departName" android:text="@string/departName" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <Spinner android:id="@+id/departNameS" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
    </TableRow>
    <TableRow >
     <TextView android:id="@+id/strComponyName" android:text="@string/accType" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <Spinner android:id="@+id/accTyte" android:layout_width="fill_parent" android:layout_height="wrap_conten t"/>
    </TableRow>
    <TableRow >
     <TextView android:id="@+id/strUserAcc" android:text="@string/userAcc" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <EditText android:id="@+id/accEditText" android:text="" android:numeric="decimal" style="@style/StyleEditText1" mce_style="@style/StyleEditText1"/>
    </TableRow>
    <TableRow >
     <TextView android:id="@+id/userPwd" android:text="@string/userPWD" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <EditText android:id="@+id/userPwdET" android:text="" android:passWord="true" style="@style/StyleEditText1" mce_style="@style/StyleEditText1"/>
    </TableRow>
    <TableRow >
     <TextView android:id="@+id/commPwd" android:text="@string/commPWD" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     <EditText android:id="@+id/commPwdET" android:text="" android:password="true" style="@style/StyleEditText1" mce_style="@style/StyleEditText1"/>
    </TableRow>
   </TableLayout>
  </LinearLayout>
  <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
    <LinearLayout android:id="@+id/linearLayoutTab1" android:layout_height="wrap_content"
     android:layout_width="fill_parent" android:orientation="horizontal">
     <LinearLayout android:id="@+id/linearLayoutTab2" android:layout_height="wrap_content"
      android:layout_width="fill_parent" android:orientation="horizontal" android:layout_weight="1">
      <CheckBox android:id="@+id/recordAcc"  android:layout_width="wrap_content" android:layout_height="wrap_content"/>
      <TextView android:id="@+id/commPwd" android:text="@string/saveUserAcc" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     </LinearLayout> 
     <LinearLayout android:id="@+id/linearLayoutTab2" android:layout_height="wrap_content"
      android:layout_width="fill_parent" android:orientation="horizontal" android:layout_weight="1">
      <CheckBox android:id="@+id/hideacc" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
      <TextView android:id="@+id/commPwd" android:text="@string/ycUserAcc" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
     </LinearLayout>  
    </LinearLayout>
   <LinearLayout android:id="@+id/linearLayoutTab1" android:layout_height="wrap_content"
     android:layout_width="fill_parent" android:orientation="horizontal">
     <LinearLayout android:layout_width="220px" android:layout_height="wrap_content" android:orientation="horizontal"
      android:gravity="center">
              <Button android:id="@+id/confirmexch" android:gravity="center" android:layout_width="wrap_content" 
         android:layout_height="50px" android:textSize="22dp" android:text="@string/login" android:layout_weight="1"
         android:focusable="false" android:t extColor="@color/white" android:background="@drawable/buttonl"/>
     </LinearLayout>
     <LinearLayout android:id="@+id/linearLayoutTab" android:layout_height="wrap_content"
      android:layout_width="fill_parent" android:gravity="center">
      <ImageView android:layout_width="wrap_content" android:layout_height="50px" android:id="@+id/myImage"/>
     </LinearLayout>
  </LinearLayout>
 </LinearLayout>
 </LinearLayout>
</ScrollView>

app_bottom.xml:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/appbottom" android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:layout_alignParentBottom="true"
  xmlns:android="http://schemas.android.com/apk/res/android">
 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:background="@drawable/light">
  <ImageView  android:id="@+id/about" android:layout_width="30px" android:layout_height="wrap_content" android:src="@drawable/ttt"
    android:layout_alignParentLeft="true"/>
  <TextView android:id="@+id/light" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"/>
 </LinearLayout>
 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:background="@drawable/mainmenu">
  <Button android:id="@+id/quotButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
  <Button android:id="@+id/entrustButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
  <Button android:id="@+id/queryButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
  <Button android:id="@+id/yinZhengButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
  <Button android:id="@+id/recordButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
  <Button android:id="@+id/loGoutButton" android:layout_weight="1" android:layout_width="52px" android:layout_height="wrap_content"
   android:textColor="@color/white" android:text="" android:background="@drawable/button1"/>
 </LinearLayout>
</LinearLayout>

tradelogin_portrait.xml:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" style="@style/StyleLayoutMain" mce_style="@style/StyleLayoutMain"
 xmlns:android="http://schemas.android.com/apk/res/android">
 <!-- include标签内不能设置RelativeLayout属性,如android:layout_alignParentBottom,因为不起作用 -->
 <!-- include标签内设置id属性后(android:id),其引用的布局layout内的id属性就不起作用了,怀疑是 其引用的layout外层包裹了一层include标签
  或者是覆盖了其内的属性id-->
 <!-- 如果没有include标签,所有布局代码都写在一个xml文件中,界面会显得很冗余,可读性很差。而且界面加载的时候是按照顺序加载的,前面的布局不能
  调用其后面的布局id。而采用include后,一个include中可以引用其后的include中的布局id属性 -->
 <include android:id="@id/titleLayout" layout="@layout/app_title" />
 <include layout="@layout/app_tradelogin"/>
 <include layout="@layout/app_bottom"/>
</RelativeLayout>

效果如下:

您可能感兴趣的文章:Android抽象布局——include、merge 、ViewStub详解Android编程之include文件的使用方法Android中使用include标签和merge标签重复使用布局android使用include调用内部组件的方法Android开发之merge结合include优化布局Android开发技巧之ViewStub控件惰性装载深入分析Android ViewStub的应用详解Android组件ViewStub基本使用方法详解Android布局技巧之include、merge与ViewStub标签的巧用


--结束END--

本文标题: 解析android中include标签的使用

本文链接: https://www.lsjlt.com/news/27482.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • html include标签的用法详解
    HTML的include标签是一种用于在HTML文件中包含其他文件内容的标签,它可以将一个外部文件的内容嵌入到当前的HTML文件中。...
    99+
    2023-08-29
    html
  • python include标签如何使用
    这篇文章主要介绍了python include标签如何使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python include标签如何使用文章都会有所收获,下面我们一起来看看吧。inc...
    99+
    2023-07-05
  • Android布局文件中include标签的作用是什么
    当使用 <include> 标签时,可以在一个布局文件中引入另一个布局文件的内容。这个被包含的布局文件可以包含一组 UI...
    99+
    2024-04-08
    Android
  • python include标签的使用方式及说明
    目录include标签如何使用?include标签的使用截图如下总结include标签如何使用? include标签的使用 在讲python include标签使用之前,我们新建一个...
    99+
    2023-03-02
    python include标签 include标签的使用 python include
  • mybatis中映射文件include标签的应用
    目录mybatis映射文件include标签应用1.引用同一个xml中的sql片段2.引用公用的sql片段3.对于多个xml文件需要同时引用一段相同的mybatis sql xml ...
    99+
    2024-04-02
  • <include>标签在mybatis中的作用是什么
    <include>标签在mybatis中的作用是什么?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。MyBatis中sql标签定义SQL片段,include标签引...
    99+
    2023-06-06
  • Android shape与selector标签使用详解
    目录shapecorners 圆角stroke 边框solid 填充背景色gradient 渐变圆形背景ripple 水波纹selector 标签文本选中变色示例checkbox选中...
    99+
    2024-04-02
  • python 中 lxml 的 etree 标签解析
    目录一、安装二、创建标签三、添加子节点四、删除子节点五、删除所有子节点六、操作子节点七、获取父节点八、创建属性九、获取属性十、设置标签文本十一、xpath方法十二、判断文本类型十三、...
    99+
    2024-04-02
  • Mybatis中typeAliases标签和package标签使用
    目录typeAliases标签和package标签的使用1、typeAliases2、packageproperties,typeAliases,package三个标签使用以及细节t...
    99+
    2024-04-02
  • DreamWeaver中p标签br标签的使用方法
    小编给大家分享一下DreamWeaver中p标签br标签的使用方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!DreamWeaver中输入的文字,想要换换,我们...
    99+
    2023-06-08
  • HTML5中的新标签和常用标签详解
    本篇内容介绍了“HTML5中的新标签和常用标签详解”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!HTML5...
    99+
    2024-04-02
  • PHP中include和require的使用详解
    在PHP中,有两种包含外部文件的方式,分别是include和require。他们之间有什么不同呢? 如果文件不存在或发生了错误,require产生E_COMPILE_ERROR级别...
    99+
    2024-04-02
  • resultMap标签中里的collection标签详解
    目录resultMap标签中的collection标签collection(一对多)collection标签中各属性的说明resultMap标签中的collection标签 coll...
    99+
    2024-04-02
  • HTML的div标签使用实例分析
    本篇内容介绍了“HTML的div标签使用实例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! &nbs...
    99+
    2024-04-02
  • Spring P标签的使用详解
    目录Spring P标签的使用本例设计对象Topic、Speech和Speakerspring配置p标签问题今天学习spring遇到这样的一个问题解决方法如下Spring P标签的使...
    99+
    2024-04-02
  • HTML中sup标签和sub标签如何使用
    本篇内容主要讲解“HTML中sup标签和sub标签如何使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“HTML中sup标签和sub标签如何使用”吧! 在HT...
    99+
    2024-04-02
  • Mybatis sqlMapConfig.xml中的mappers标签使用
    目录sqlMapConfig.xml中的mappers标签mappers(映射配置)1.1:通过resource加载单个映射文件1.2:通过mapper接口加载单个映射文件1.3:批...
    99+
    2024-04-02
  • 如何深入剖析DIV标签的使用
    如何深入剖析DIV标签的使用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。向大家描述一下DIV标签的使用,DIV标签称为区隔标...
    99+
    2024-04-02
  • HTML Noscript 标签百科全书:全面解析标签用法和作用
    一、HTML Noscript 标签简介 Noscript 标签是一个 HTML 元素,它允许您在网页中禁用 JavaScript。当浏览器遇到 Noscript 标签时,它将停止执行所有嵌入在该标签之间的 JavaScript 代码。...
    99+
    2024-02-10
    HTML Noscript 标签 禁用 JavaScript 安全性 隐私 性能
  • php中的include怎么使用
    今天小编给大家分享一下php中的include怎么使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。在PHP中,includ...
    99+
    2023-06-29
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作