This is the fifth day of my participation in the August More text Challenge. For details, see:August is more challenging
Preface: Introduction to practice series
Series of practice and basic series are related knowledge about Android development, the difference is that basic series based on knowledge points, mainly introduces the application of the content and related knowledge, is a separate “dot”, but practice series from requirement, tells how to implement step by step, will involve a lot of knowledge in the process, quite so basic series of complement.
Due to the large amount of code in the practice series, it is not possible to expand every detail carefully. When in doubt, you can go to Github to view the completed project code, or directly comment and ask questions.
Requirement description: copy the home page of Nuggets App
This practice is to copy the nuggets App home page, only fake data to imitate the UI effect, after all, nuggets also did not develop API can be used.
I think you are all familiar with what the front page of the Nuggets looks like. I recorded a GIF but it doesn’t work very well.
Demand for resolution
From the perspective of hierarchy, the bottom navigation in the page is fixed. Click the bottom navigation to switch the main content, so the Activity only needs the bottom navigation and a container, and the View inside the container is dynamically created as the user operates.
Instead of creating a View object directly through Kotlin code, the Android API provides a class called Fragment that gives a View a lifetime and can be managed by tying it to an Activity.
Five subpages through Fragment, home page, boiling point and found page content is more complex, should need to encapsulate a RecyclerView to reduce boilerplate code, interactive effect also have to slightly fine tune the details. The home page is somewhat similar to the content found, and the ViewHolder of the list can be reused. Both the booklet and my pages are relatively monotonous lists that are not very difficult to implement.
The final part is divided into five parts:
- Add base dependencies and bottom navigation scaffolding
- RecyclerView simple encapsulation, realize the “brochure” and “me” page
- Implement the “home page”
- Realize discovery
- Achieving the boiling point
1. Set up the bottom navigation
To add dependencies is to modify build.gradle to add third-party libraries that need to be used. The specific libraries used will be written from the basic series later.
The bottom navigation of the mining is Material Design style and can be implemented directly with the BottomNavigationView of the Design library.
Material Design is a Design style of Google. The Android API provides many Material Design style views for developers to use. Following the Material Design specification can significantly reduce development costs and unify the App style on the phone. However, the mainstream Design in China is iOS style, and Material Design is not commonly used.
ConstraintLayout is used on the layout, which contains only BottomNavigationView and an empty FrameLayout.
The contents of BottomNavigationView are configured through menu, which is a kind of classification under RES (corresponding to res/menu/ folder). Because it is not commonly used, the default project template will not create the corresponding folder. Create your own folder when you need to use it.
After setting the menu, you can see the navigation content in the preview panel. Other style adjustments can also preview the effect. I have to say that the official View support is more perfect. And then I’m going to have to add some code and I’m going to click on the FrameLayout.
The basic use of a Fragment is to add its own View to the entire View tree by adding or replacing it. In this case, let’s temporarily select Replace to see what happens.
Effect display:
“
At the very beginning of practice, I obviously feel that the basic content is still too little written. Once the code is mentioned above, there is a certain difference between learning and practice. Simple learning is difficult to integrate, and simple practice is difficult to form a complete knowledge system.
Have a great weekend!