zoukankan      html  css  js  c++  java
  • fragment入门

    [1]在activity布局中定义fragment

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment android:name="com.itheima.fragment.Fragment1"
                android:id="@+id/list"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent" />
        <fragment android:name="com.itheima.fragment.Fragment2"
                android:id="@+id/viewer"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent" />
    </LinearLayout>

    [2]声明fragment

    import android.app.Fragment;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    //定义一个Fragment 
    public class Fragment1 extends Fragment {
    
        //当用户第一次画ui的时候调用  要显示Fragment自己的内容  setContentView(R.layout.activity_main);
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            //[1]通过打气筒把一个布局转换成view对象 
            View view = inflater.inflate(R.layout.fragment1, null);
            
            
            return view;
        }
    }

    [3]name属性 要指定我们自己定义的fragment

  • 相关阅读:
    SE知识整理——泛型
    IDEA 运行 SpringMVC 项目分发控制器出现404解决方案。
    快速幂/欧拉降幂
    Leetcode(双指针专题)
    剑指offer
    ns3参考
    网络知识1:最后一公里/WiMax / 4G
    备份2
    shell入门
    ns3_gdb:协议里的函数是怎么被调用的
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6099180.html
Copyright © 2011-2022 走看看