zoukankan      html  css  js  c++  java
  • Fragment的基本用法

    此处使用android-support-v4.jar。

     一.
    当创建包含Fragment的Activity时,如果用的是Support Library,那么继承的就应该是FragmentActivity而不是Activity。

     二.写Fragment的Layout。
     
     三. 新建ExampleFragment类。onCreateView()方法中指定布局文件。
     public static class ExampleFragment extends Fragment
    {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState)
        {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.example_fragment, container, false);
        }
    }
     三. 通过Activity的布局文件将Fragment加入Activity

          在Activity的布局文件中,将Fragment作为一个子标签加入即可。其中android:name属性是你自己创建的fragment的完整类名。
     <fragment
            android:id="@+id/list"
            android:name="com.yang.tab.Fragment1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

     四.  或通过编程的方式将Fragment加入到一个ViewGroup中

            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            
            ExampleFragment fragment = new ExampleFragment();
            fragmentTransaction.add(R.id.linear, fragment);
            fragmentTransaction.commit();

            其中add()方法第一个参数是要插入的父控件组的资源ID。 
  • 相关阅读:
    python模块之datetime方法详细介绍
    练习十七:python辨别数据类型
    练习十六:Python日期格式应用(datetime)
    Tkinter的l组件常用属性
    Log4net使用方法
    Thinkphp中在本地测试很好,在服务器上出错,有可能是因为debug缓存的问题
    Git 常见问题
    Linq中的in和not in的使用方法
    网络协议
    WCF传输协议
  • 原文地址:https://www.cnblogs.com/yangleda/p/4149427.html
Copyright © 2011-2022 走看看