人生到头来,就是不断放下,但永远最|

durtime

园龄:4年8个月粉丝:10关注:1

每日日报

fragment入门
通过xml文件声明fragment
创建Fragment的布局文件 xml
①创建一个类继承Fragment
②重写onCreateView方法 把fragment对应的xml布局文件加载进来  在这个方法中创建fragment的界面
  1. public class FirstFragment extends Fragment {
  2. @Override
  3. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  4. Bundle savedInstanceState) {
  5. //把fragment 对应的xml布局文件文件 转换为View对象 加载到界面上
  6. View view = inflater.inflate(R.layout.fragment_first, null);
  7. return view;
  8. }
  9. }
 
③ 在activity的布局文件中 声明一个fragment节点 ( fragment要小写  一定要声明一个id )
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:orientation="horizontal"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5. <fragment android:name="com.itheima.fragmentdemo.FirstFragment"
  6. android:id="@+id/list"
  7. android:layout_weight="1"
  8. android:layout_width="0dp"
  9. android:layout_height="match_parent" />
  10. <fragment android:name="com.itheima.fragmentdemo.SecondFragment"
  11. android:id="@+id/viewer"
  12. android:layout_weight="2"
  13. android:layout_width="0dp"
  14. android:layout_height="match_parent" />
  15. </LinearLayout>

本文作者:durtime

本文链接:https://www.cnblogs.com/durtime/p/14836470.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   durtime  阅读(41)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开