抱歉,我是Fragments的新手。我正在使用像这样的片段:
<fragment
android:name="com.example.lesson1.Fragment1"
android:id="@+id/activity_fragment1"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"
/>
我知道 src 文件夹中名称属性对类的引用,但是:
- 这里的android:name="com.example.lesson1.Fragment1"
属性究竟是什么?
- 它的用途是什么?
答案 0 :(得分:2)
引用文档。
android:name
中的<fragment>
属性指定要在布局中实例化的Fragment类。
当系统创建此活动布局时,它会实例化布局中指定的每个片段,并为每个片段调用onCreateView()方法,以检索每个片段的布局。系统直接插入片段返回的视图代替元素
这是在xml中声明片段的时候。
除了上述内容之外,您可能还有兴趣检查一下。