Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用拖放功能在我的活动中添加线性布局。当我检查 activity_main.xml 时,创建了组件但没有“android:id”我无法手动添加 id,因为在 R.java 中没有此布局的 id。如何解决?
如果您将 android:id="@+id/YOUR_ID" 添加到您的 XML,您的 IDE(我假设是 eclipse)将重新编译 R.java,并且您应该能够在您的活动中使用 R.id.YOUR_ID。
您无需使用 R.id 以编程方式设置 id。您可以使用任何正数作为 id:
myNewLayout.setId(newLayoutIndex);
根据查看文档
标识符在此视图的层次结构中不必是唯一的。标识符应该是一个正数。