Fragment was added after 3.0, because the tablet screen is too large, an activity first is too monotonous, this time there is a fragment.
Look at its life cycle first, because the life cycle of fragment is dependent on activity.
Fragment commonly used in three classes:
Android.app.Fragment is primarily used to define Fragment
Android.app.FragmentManager is primarily used to operate in activity fragment
Android.app.FragmentTransaction to ensure that some of the column fragment operation of the atom, familiar with the word business, you will understand ~
A, the way to obtain Fragmentmanage:
Getfragmentmanager ()//V4, Getsupportfragmentmanager
b, the main operation is the method of Fragmenttransaction
Fragmenttransaction transaction = Fm.bengintransatcion ();//Open a transaction
Transaction.add ()
Add a fragment to the activity
Transaction.remove ()
Remove a fragment from the activity, if the removed fragment is not added to the fallback stack (which is detailed later in the fallback stack), the fragment instance will be destroyed.
Transaction.replace ()
Replace the current with another fragment, which is actually the fit of remove () and then add () ~
Transaction.hide ()
Hides the current fragment, is only set to invisible, and does not destroy
Transaction.show ()
Show previously hidden fragment
Detach ()
The view is removed from the UI, unlike remove (), where the state of the fragment is maintained by Fragmentmanager.
Attach ()
Rebuilds the view view, attaches to the UI, and displays.
Transatcion.commit ()//Commit a transaction
The study of Fragmet