• fragment用法


    简单用法:

      1.新建布局、新建fragment类

      2.在activity_main.xml中添加fragment

    <LinearLayout......
        <fragment
            android:orientation="horizontal";
            android:name="com.example.fragment.LeftFragment"  //完整的包名、类名
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    ......

    动态加载fragment:

      1.创建待加载的fragment实例

      2.获取FragmentManager,通过getSupportFragmentManager():FragmentManager fragmentManager = getSupportFragmentManager();

      3.调用beginTrasaction()方法开启事务:FragmentTransaction transaction = fragmentManager.beginTransaction();              

      4.向容器中添加或替换碎片,一般使用replace()方法实现,需要传入容器的id和待添加的碎片实例:transaction.replace(R.id.right_layout,fragment);

      5.提交事务:transaction.commit();

      使用限定符:大小:small、normal、large、xlarge

            分辨率:ldpi、mdpi、hdpi、xhdpi、xxhdpi

            方向:land、port

            最小宽度:layout-sw600dp(小于600dp加载默认layout布局,大于600加在此layout)

      

  • 相关阅读:
    区块链
    黑帽内容整理
    编程语言
    编程语言
    PHP
    安全体系建设-OWASP
    burp
    编程语言-Python-GUI
    加解密
    结合自己的程序对thinkphp模板常量的理解
  • 原文地址:https://www.cnblogs.com/yl-saber/p/6401814.html
Copyright © 2020-2023  润新知