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
According to foreign media reports, recent studie...
In the four years since the birth of LeTV Super T...
On November 19, 2024, the "Second Intelligen...
Since last year, consumption has once again becom...
Recently, negative news about Kris Wu has continu...
With the rise of short video platforms, more and ...
Daily special offers are the dream of every Taoba...
The number of participants in the car-sharing sec...
In the movie Spider-Man The hero was bitten by a ...
Expert of this article: Fu Lu, Master of Neurophy...
The film screenwriting master video course teaches...
Seeing the first batch of color photos released b...
The ultimate goal of search advertising is to bri...
Can microbes communicate with alien species? Sunr...
As a video operator platform, iQiyi has developed...