Android使用include无法调整位置的解决方法
来源:互联网 发布:我知女人心 电影粤语 编辑:程序博客网 时间:2024/05/16 16:15
在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的。例如:
<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上找到了更好的解决方法:
解答道:必须同时重载layout_width和layoutheight熟悉,其他的layout*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:
<include layout="@layout/otherlayout"> android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_below="@id/top" />
另外,关于xml的复用,还可以使用merge标签,merge标签主要是用来优化显示的,减少View树的层级,可以参考这里:https://developer.android.com/resources/articles/layout-tricks-merge.html 翻译版在这里:http://apps.hi.baidu.com/share/detail/20871363
原文链接:http://www.race604.com/using-include-in-layout/
- Android使用include无法调整位置的解决方法
- Android使用include无法调整位置的解决方法
- xcode无法include vector的解决方法
- Android手机无法使用debug的解决方法
- include 布局android:layout_below属性无法使用
- Android学习篇:Toast位置的调整
- iOS - Xib拖放上面的控件无法调整其位置
- Win7、Win8无法include stdio.h的解决方法
- 使用ViewTreeObserver动态调整控件位置(Android)
- Android中include的使用
- android include控件的使用
- Android include标签的使用
- android viewstub include的使用
- Android include标签的使用
- android include 标签的使用
- android中的include的使用
- html无法使用include
- 调整leftBarButtonItem 的位置
- 令Ubuntu开机直接进入控制台,不启动x window
- poj1426
- CVPR2012——Ali Borji的三篇saliency
- 同一个dom元素下 单击事件覆盖双击事件的解决方法
- 第三周项目3-求集合并集
- Android使用include无法调整位置的解决方法
- 第三周实践项目~求集合并集
- 定义单链表存储结构,用头插法和尾插法建立单链表,并显示建立好以后的结果。
- 播放视频
- Myeclipse10下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3
- 随想
- nginx+rtmp实现视频直播
- setsockopt()用法(参数详细说明)
- app版本信息