本文是结合学习第一行代码3 中Fragment章节的时候,我在练习FragmentBestPractise project时,相比于书里的code, 我用了viewbinding代替了kotlin extensions,也由此引入一些问题,相关内容的一些总结:
1. Configurations for activity_main.xml must agree on the root element's ID
这个问题发生在写了根据不同适配的layout xml。这里注意,两个布局的根元素的 id 必须一致!
解决这个问题的办法,就在布局外面都套一层布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/newsTitleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/newsTitleFrag"
android:name="com.nxp.fragmenttest.NewsTitleFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"