展会信息港展会大全

布局优化:include标签,简化重复代码
来源:互联网   发布日期:2016-01-14 12:13:48   浏览:1667次  

导读:?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 TextVi...

<?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>

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

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" />

</RelativeLayout>

赞助本站

人工智能实验室

相关热词: android开发 android教程

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港