Last time I talked about using themes and applying the Material Design style. At the same time, card layout is also an important part of Material Design. Let’s write about it today. introduction To create complex Material Design style List and Card in the program, you can use RecyclerView and CardView components, which are provided in the *** support v7 package (version 21). Therefore, you need to introduce the dependent package:
Creating a List The RecyclerView component is a more efficient and flexible ListView. This component is a container for displaying large data sets, which can scroll efficiently and keep a certain number of views displayed. Use the RecyclerView component when you have a data set and the elements of the data set change at runtime based on user operations or network events. The RecylerView class simplifies the display and processing of large data sets by providing: Layout managers control the positioning of elements. Displays default animations for common element operations, such as removing and adding elements. To use the RecyclerView component, you need to specify an Adapter and a layout manager. Create an Adapter that extends the RecyclerView.Adapter class. The specific implementation details vary depending on the type of data collection view. For more information, see the following example. A layout manager positions the Item view in the RecyclerView and decides when to recycle it when it is no longer visible. When reusing (or recycling) a view, the layout manager may request the adapter to replace the content in the subview with different content. Recycling and reusing views in this way can reduce the creation of views and avoid more findViewById(), thereby improving performance. RecyclerView provides the following built-in layout managers:
StaggeredGridLayoutManager displays Item in a staggered grid layout. You can also create your own custom layout manager by inheriting the RecyclerView.LayoutManager class. RecylerView Component Animation: RecyclerView has animation by default when deleting or adding Items. If you need a custom animation, inherit the RecyclerView.ItemAnimator class and use the RecyclerView.setItemAnimator() method to set the defined animation to our view. Let's start with an example: 1. First add a RecyclerView to the xml layout file
2. Then use it in our Java code, attach the Adapter and data and it will be displayed.
3. The Adapter provides access to the Items in the data set, creates a view mapped to the data, and replaces the content data of the layout with the new item. The following code shows a simple implementation, using a TextView to display a simple String array.
Create Card CardView inherits the FrameLayout class, which allows you to display information inside the card and have a unified style on different platforms. The CardView component can have shadows and rounded corners. To create a card with a shadow, use the card_view:cardElevation property. CardView uses real height and dynamic shadows on Android 5.0 (API 21) and higher, and earlier versions use traditional shadows. Use these properties to customize the appearance of CardView:
To set the background color of a card, use the card_view:cardBackgroundColor attribute. Here is an example of including a CardView in an XML layout file:
Card example image Random From the above, you can see RecyclerView. It is very similar to the ListView we often use, but its parent class is not AbsListView, so it cannot be used together. However, it can replace ListView in many places. Through ViewHolder and View reuse, you can see that this is a more efficient view component and is recommended. CardView is essentially a component that is more in line with Material Design. It uses Card layout for better results. Many people may have used CardUi before. Google officially released this and it is highly recommended. The RecyclerView and CardView above are written separately, but we can use them together, don't be confused. Reference: http://developer.android.com/training/material/lists-cards.html Original address: http://blog.isming.me/2014/10/21/creating-app-with-material-design-two-list/, please indicate the source when reprinting. |
<<: Android common tools source code collection
>>: WeChat Enterprise Accounts Dialogue with Enterprise Mobile Platform
Thales, an ancient Greek mathematician and philos...
Whether it is a WeChat avatar, a QQ avatar, or an...
Overview of Alipay System Architecture Typical pr...
The main purpose of push is to promote activation...
[[196882]] 1. Introduction Recently, a new versio...
A major study found that by 2030, the electricity...
Ye Tan Finance "2021 Tan Tan Bull and Bear E...
Nowadays, when talking about marketing, if you do...
There are some things that you cannot think about...
Produced by | Science Popularization China Author...
[[411358]] I believe that friends who have checke...
In autumn, we see a lot of fallen leaves, fruits,...
This article shares all aspects of direct-operate...
Q: How to choose marketing promotion channels ? A...
Talking about data analysis theory alone is too d...