在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上找到了更好的解决方法: 解答道:必须同时重载layoutwidth和layoutheight熟悉,其他的layout_*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:

<include layout="@layout/otherlayout">    android:layout_height="wrap_content"    android:layout_width="fill_parent"    android:layout_below="@id/top" />

更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. android EditText设置不可写
  3. Android开发——Android搜索框架(二)
  4. Android(安卓)Activity的启动
  5. APP开发实战94-Vector静态图的使用
  6. [Android] ACTION_GET_CONTENT与ACTION_PICK的区别
  7. Android(安卓)开发中的倒计时
  8. Android(安卓)UI系列 - 布局 - 目录
  9. Gradle多渠道打包

随机推荐

  1. MySQL索引失效的典型案例
  2. MySQL库表名大小写的选择
  3. mysql 带多个条件的查询方式
  4. Mysql 如何实现多张无关联表查询数据并分
  5. Mysql中存储引擎的区别及比较
  6. 浅谈mysql返回Boolean类型的几种情况
  7. Mysql 设置boolean类型的操作
  8. MySQL中的布尔值,怎么存储false或true
  9. mysql外连接与内连接查询的不同之处
  10. Mysql systemctl start mysqld报错的问题