In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.