Android fragment-Design Philosophy

Source: Internet
Author: User

Android introduces fragment in android3.0, which is mainly used to support more dynamic and flexible UI design on large screens, such as tablets. Because the screen size of a tablet is larger than that of a handheld device, more space is available for combination and interchange of UI components. Fragment allows you to manage the design method of complex management of the view layer tree. By breaking the layout of an activity into different fragment, You can edit the appearance of the activity at runtime and keep these changes in the rollback stack managed by the activity.

For example, a news application can use a fragment on the left to display the article list, use another fragment on the right to display an article -- the two fragment are displayed in the same activity in parallel, in addition, each fragment has its own lifecycle callback method and a set of user input events for processing. In this way, you will not use an activity to select an article, but read the article in another activity, as described in 1 (tablet layout ), you can select and preread an article in the same activity.

Figure 1 how to combine the two UI modules defined by fragment into an activity on a tablet, and how to separate them in a handheld device.

You should design each fragment into a module and reusable Activity component. This is because each fragment defines their own layout and has their own lifecycle behavior. You can include one fragment in multiple activities, so you should design it into reusable, in addition, you must avoid direct operations from one fragment to another. This is especially important because a modular fragment allows you to change your fragment combination for different screen sizes. When an application is being designed to support both tablet and handheld devices, you can reuse fragment in different layout configurations to optimize user experience based on effective screen space. For example, on a handheld device, when multiple fragment cannot be filled in the same activity at the same time, separate UI panels must be provided for these fragment.

For example, if you continue to use the news application as an example, when running on a tablet, Activity A can be embedded with two fragment, while on the screen of a handheld device, there is not enough space to include the two fragment. Therefore, activity a only contains the fragment for the article list. When you select an article, it starts Activity B, it contains the second fragment used to read the article. In this way, as stated in 1, applications use different combinations to reuse fragment to support tablets and handheld devices.

For how to design programs with different fragment combinations to adapt to different screen configurations, see support for tablets and handheld devices (supporting tablets and handsets ).

Related Article

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.