Android在layout xml中使用include
2016-01-30 10:49
477 查看
在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的。例如:
Android开发的官方网站的说明在这里。
其中,有提到:
Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the
意思是任何android:layout_*属性都可以应用在标签中。
如果使用如下代码:
发现
有解决方法是在include的外面再包一层LinearLayout,如下:
在Statckoverflow上找到了更好的解决方法: 解答道:必须同时重载layoutwidth和layoutheight熟悉,其他的layout_*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:
<include layout="@layout/otherlayout"></div>
Android开发的官方网站的说明在这里。
其中,有提到:
Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the
<include>tag.
意思是任何android:layout_*属性都可以应用在标签中。
如果使用如下代码:
<Relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <Textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/somestring" android:id="@+id/top" /> <include layout="@layout/otherlayout" android:layout_below="@id/top" /> </Relativelayout >
发现
include的otherlayout,并没有在如我们预期的在id/top这个TextView下面,而是忽略了android:layout_below属性。经过Google发现,很多人遇到类似的问题。
有解决方法是在include的外面再包一层LinearLayout,如下:
<Linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/top" > <include layout="@layout/otherlayout"> </Linearlayout >
在Statckoverflow上找到了更好的解决方法: 解答道:必须同时重载layoutwidth和layoutheight熟悉,其他的layout_*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:
<include layout="@layout/otherlayout"> android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_below="@id/top" />
相关文章推荐
- Android中的对话框(二)ProgressDialog
- Android进阶之路——自定义NumberPicker
- Android 第五天(上午)
- Android 中的 Service 全面总结
- 【Android】AS环境下,在布局中使用android:gravity="left/right"提示使用start/end
- Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)来传递参数
- android 百度地图开发打包注意点
- Android 蓝牙2.0的使用方法:
- Android笔记 - Binder之servicemanager代理对象
- android 解决clean一下工程R文件丢失的问题
- Win7使用SecureCRT远程访问Ubuntu14.04
- 《Android开发艺术探索》读书笔记 (1) 第1章 Activity的生命周期和启动模式
- android和javascript之间相互通信实例分析
- android和javascript之间相互通信实例分析
- android和javascript之间相互通信实例分析
- Android开发JDBC连接mysql数据库导入驱动方法
- android原生TabLayout+viewpaper+fragment实现滑动效果
- 安卓开发——AndroidStudio中获取联网权限
- Android使用videoview播放res/raw下的视频
- Android开发辅助工具之GitHub