Piglet's Android starter Road Day 5-part 2

Source: Internet
Author: User

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^)/





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.