Piglet's Android starter Road Day 5-part 2
Activity fragment: Fragment (Shard)
------Reprint Please specify the Source: Coder-pig
Introduction to this section:
In Part 1 We have detailed analysis of the basic unit activity of Android, and in Part 2 we will explain
Activity fragment: Fragment (Shard), initially designed to simplify the UI design of a large-screen phone or tablet, but is now commonly used
Ordinary mobile phone, such as fragment + Slidemenu to achieve side-slip effect , there are many relevant examples on the Internet, master the basic usage of fragment
It's easier to understand the code for some of the effects of using fragment!
OK, just start this section!
Learning Roadmap for this section:
Body:
Overview of fragment and life cycle diagram:
process for creating fragment
① static load fragment:
code example:
Divide activity into two fragment
As follows:
Relatively simple, the code is not listed, you need to download it: reference code download
Ps:fragment subclasses are:
dialog box:dialogfragment list:listfragment
option settings:preferencefragment WebView Interface:webviewfragment
② dynamic Load Fragment
code example: switching between fragment and replace
When we load different fragment when we switch the screen, we write the method of dynamically loading fragment in the activity's OnCreate () method
When we switch the screen, the activity will be destroyed and then loaded from the new!
The code is also very simple, to download it yourself: code Download
fragment interaction with the activity
fragment management and fragment affairs
code example: Click on the list item on the left to display the appropriate details on the right:
As follows:
When vertical screen:
At horizontal screen:
This code is a bit difficult for beginners to understand: but it is a relatively simple example, compared to the slippery side:
You have to wonder! Reference code Download: code Download
The basics of ps:fragment are so much for the time being, fragment is an important part of Android UI development,
In the future will be combined with examples to explain! There will be further lectures in the future! Thank you \ (^o^)/