Android 使用include需要注意的坑

来源:互联网 发布:ubuntu文件备份命令 编辑:程序博客网 时间:2024/05/21 18:45

若你在include的layout中的父View,声明了其id,如:
该布局xml命名为: layout_a.xml
id为layout_a

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/layout_a"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@color/whilte"    android:orientation="vertical" >     <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:gravity="center"            /></RelativeLayout>

在其他布局中使用include引用改布局时,就不能再声明id了,那么就会报错。只能声明一次。

以下的使用就是错误的。

<include      android:id="@+id/layout_a"      layout="@layout/layout_a"/>
1 0
原创粉丝点击