zoukankan      html  css  js  c++  java
  • 大叔程序员的第二天 @Fragment学习

    Fragment生命周期类似于Activity。

    用于分屏显示功能。

    使用可继承Fragment类或者其三个子类:DialogFragment,ListFragment,PreferenceFragment。

    文库的学习资料http://wenku.baidu.com/view/13fa98c008a1284ac8504331.html介绍的比较全。

    举个2个创建Fragment的例子,下面是一个由2个Fragment组成的Activity

    例子是一个有2个fragment的activity:  <?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.example.news.ArticleListFragment"  

        android:id="@+id/list"              

        android:layout_weight="1"              

        android:layout_width="0dp"              

        android:layout_height="match_parent" />      

      <fragment android:name="com.example.news.ArticleReaderFragment"              

        android:id="@+id/viewer"              

        android:layout_weight="2"              

        android:layout_width="0dp"              

        android:layout_height="match_parent" />    

    </LinearLayout> 

    而如果想通过无UI的方法调用Fragment,则可通过要添加一个无UI的fragment, 需要从activity使用 add(Fragment, String) 来添加 fragment

    (为fragment提供一个唯一的字符串"tag", 而不是一个view ID).这么做添加了fragment, 但因为它没有关联到一个activity layout中的一个view,

    所以不会接收到onCreateView()调用. 因此不必实现此方法.

    管理Fragment


    常用的方法如getFragmentManager(), findFragmentById(),findFragmentByTag()

  • 相关阅读:
    【POJ1961 Period】【KMP】
    浅谈KMP算法
    【关于动态开点线段树】
    【POJ3349 Snowflake Snow Snowflakes】【Hash表】
    【NOI 2002 银河英雄传说】【带权并查集】
    路径问题
    group_concat函数详解
    MySQL中GROUP_CONCAT中排序
    怎么实现CSS限制字数,超出部份显示点点点.
    jsp去掉小数点
  • 原文地址:https://www.cnblogs.com/linxiaojiang/p/2944314.html
Copyright © 2011-2022 走看看