In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
 
            
                     
                
2025-10-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to use fragment to achieve fragmented layout in Android. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Fragment can actually be understood as a control with its own life cycle, but this control is a little special. It has its own ability to handle input events, has its own life cycle, and must rely on Activity to communicate and host each other.
There are several other advantages to using Fragment:
Code reuse. It is especially suitable for modular development, because a Fragment can be nested by multiple Activity and can be reused with a common business module. It is a good component of modular UI.
Activity is used to manage Fragment. The life cycle of Fragment is pinned to Activity, and Fragment can be added by Attach and released by Detach.
Controllability. Fragment can be created and controlled as freely as ordinary objects, it is easier and convenient to transfer parameters, and there is no need to deal with system-related matters. Display mode, replacement, whether whole or part, can be changed accordingly.
Fragments is view controllers, they contain testable, decoupled business logic blocks, because Fragments is built on views, and views is easy to achieve animation effects, so Fragments has better control when switching screens.
Activity_login.xml
 
The empty space in the middle
 
Let's just add a LinearLayout and call it login_fragment.
LoginActivity
Key code
The above defines the Fragment for our account login and gesture login, and then uses a CreateFrag to create header and body fragments.
Then define a Logintype as an integer to distinguish between current account login and gesture login. Then the SetLoginType function is used to switch the effect of our fragment according to different types.
Account login
Fragment_login_input.xml
LoginInputFragment
Gesture landing
Fragment_login_sign.xml
Let's find another article about gesture landing.
LoginSignFragment
This is how to use fragment to achieve fragmented layout in Android shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about

The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r


A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from

Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





 
             
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.