• 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。 
  • 相关阅读:
    欧拉公式求四面体的体积
    欧拉公式求四面体的体积
    I
    I
    闭包传递(floyed)
    闭包传递(floyed)
    Python hypot() 函数
    Python cos() 函数
    Python atan2() 函数
    Python atan() 函数
  • 原文地址:https://www.cnblogs.com/yangleda/p/4149427.html
Copyright © 2020-2023  润新知