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

  • 相关阅读:
    安装node-gyp
    node版本切换
    electron-vue运行只出现项目目录不出现效果
    高级运维工程师的必备技术
    linux 下的shutdown指令
    数据库实体联系模型与关系模型
    数据库表设计1
    实体-关系模型
    Excel中怎么快速选中区域
    EXCEL中给包含某个字段的单元格所在行标注颜色
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6099180.html
Copyright © 2011-2022 走看看