安卓 坑爹的 include 标签
来源:互联网 发布:朋友借身份证开淘宝店 编辑:程序博客网 时间:2024/06/05 08:41
在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include /> 标签来重用layout代码。相当于html的include。
但是用这个标签忽然引用后的样式和被引用的样式居然不一样。。。见代码
usercenter_userinfo.xml 被引用的文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="@drawable/suma_selector_usercenter_item_round"
android:orientation="horizontal"
android:paddingLeft="10.0dip" >
.此处省略内部布局...
</RelativeLayout>
引用布局的文件:
<LinearLayoutandroid:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
layout="@layout/usercenter_userinfo" />
</LinearLayout>
明显看到,高度等样式居然变了。。
经过折腾,修改代码。。如下
<?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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="@drawable/suma_selector_usercenter_item_round"
android:orientation="horizontal"
android:paddingLeft="10.0dip" >
. 此处省略内部布局...
</RelativeLayout>
</LinearLayout>
样式终于正常了。。
总结:
安卓的include标签,有点让人疑惑,至于为什么子文件中的最外层布局为什么设置高度不生效。不太理解。反编译QQLive学习了下,他们也是嵌套了一层。
另外从文章 http://blog.csdn.net/liuzhidong123/article/details/7389745 可以看出,嵌套的xml文件可以不使用任何viewgroup布局。
如果你对include有高深的见解,请回复。
- 安卓 坑爹的 include 标签
- 安卓include文件踩过的坑
- android的include标签
- include标签的使用
- android 的include标签
- struts 的 include标签
- include标签与include指令的比较
- include指令与include标签的区别
- include指令和include标签的区别
- include,viewStub标签的使用
- Android include标签的使用
- Android include标签的使用
- android include 标签的使用
- 安卓开发之<include /><merge /><viewstub />的使用
- MyBatis_sql标签和include标签的使用
- Include标签
- include标签
- include标签
- URI URL URN简介及其在Java中的应用
- Java 3DES 加密 解密 示例
- 原文地址:C++ 语法大全。作者:Capacity
- Android版火狐:远程调试功能指南
- Android中的px, dp, dip and sp总结
- 安卓 坑爹的 include 标签
- SWT 全接触
- 有技巧的小水题 之 求最小公倍数
- struts1 logic标签的使用
- 堆和栈
- 二分查找-两已排序数组中找中位数二题
- JAVA基础之理解JNI原理
- 初学试试看cocos2dx的TestCPP框架(2) --CCApllication
- CCLabelAtlas的一点技巧