Android and android Official Website
ViewPager + Fragment
When Fragment becomes a page of ViewPager, FragmentManager keeps saving the created Fragment. Even if this page is not displayed, the Fragment object will not be destroyed, wait for the display again in the background. However, if Fragment is no longer visible, its view level will be destroyed and its view level will be re-created next time it is displayed.
Because FragmentPagerAdapter is used, the Fragment object remains in the memory, so when there are a large number of display pages, FragmentPagerAdapter is not suitable for use, FragmentPagerAdapter applies to only a few page situations, such as tabs. In this case, you can use the FragmentStatePagerAdapter. When FragmentStatePagerAdapter is used, if Fragment is not displayed, the Fragment object will be destroyed, but the onSaveInstanceState (Bundle outState) will be called back before the ondestro) method To save the Fragment status. When the next Fragment is displayed, the stored status value is obtained through onCreate (Bundle savedInstanceState). FragmentStatePagerAdapter is more suitable for scenarios with many pages, such as a page ListView.
Animation
1 FragmentTransaction ft = getFragmentManager().beginTransaction(); 2 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 3 ft.replace(R.id.details, detail); 4 ft.addToBackStack(null); 5 ft.commit();
The fade effect set by the Code.
1 FragmentTransaction ft = getFragmentManager (). beginTransaction (); 2 // setCustomAnimations () must be before replace (); otherwise, the effect will not be satisfactory. The two parameters are respectively enter and exit. The system currently provides two effects: android. r. animator. fade_in and android. r. animator. fade_out 3 ft. setCustomAnimations (R. animator. slide_in_left, R. animator. slide_out_right); 4 ft. addToBackStack (null); 5 ft. replace (R. id. details, "detail"); 6 ft. commit ();
Use setCustomAnimations ()
No parameter constructor & PASS Parameters
Fragment must have a non-argument constructor. If you want to pass a parameter to fragment, you must use the Bundle Method to pass the parameter without reloading the constructor, because the re-generated fragment will not execute this constructor with parameters, but will execute the non-argument constructor.
1 public static VechileFrag newInstance(Vehicle vehicle, String userId, boolean isAdd) { 2 VechileFrag mf = new VechileFrag(); 3 Bundle args = new Bundle(); 4 args.putString("userId", userId); 5 args.putBoolean("isAdd", isAdd); 6 args.putParcelable("vehicle", vehicle); 7 mf.setArguments(args); 8 return mf; 9 }10 11 12 @Override13 public void onCreate(Bundle savedInstanceState) {14 super.onCreate(savedInstanceState);15 Bundle args = getArguments();16 if (args != null) {17 userId = args.getString("userId");18 isAdd = args.getBoolean("isAdd");19 vehicle = args.getParcelable("vehicle");20 if (vehicle == null) {21 vehicle = new Vehicle();22 }23 }24 } Menu
1 @Override2 public void onCreate(Bundle savedInstanceState) {3 super.onCreate(savedInstanceState);4 setHasOptionsMenu(true);5 }
Then, you can call onCreateOptionsMenu.
Save the Fragment switchover
Fragment fragment = fragments.get(i);if(!fragment.isAdded()) { if(currentIndex!=-1) fragments.get(currentIndex).onPause(); ft = fm.beginTransaction(); ft.setTransition(android.support.v4.app.FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.add(R.id.framelayout,fragment); // ft.addToBackStack(null); ft.commit(); currentIndex=i;}else{ ft = fm.beginTransaction(); fragments.get(currentIndex).onPause(); ft.setTransition(android.support.v4.app.FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.hide(fragments.get(currentIndex)); ft.show(fragments.get(i)); fragments.get(i).onStart(); ft.commit(); currentIndex=i;}
I am the dividing line of tiantiao
What language is used for Android software development?
What else does Javascript proficient android ahan.
What language is used for Android software development?
What else does Javascript proficient android ahan.