我注意到一个应用程序,它的布局让我为难,来到include指令。资源ID定义使用XML布局
假设有两种布局的XML文件,这样一个包含其他:
activity_button.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/button"/>
</LinearLayout>%
button.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/button"
android:onClick="sendMessage">
</Button>
什么是按钮的资源ID?
我以为人们总是必须通过android:id
属性指定ID,所以我很困惑为什么这个布局有效。我也检查了R.java
ID条目,它似乎是空的。