Open-source project-Aiguille, open-source project

Source: Internet
Author: User

Open-source project-Aiguille, open-source project

Project address: https://github.com/wwkai555/Aiguille

 

This project mainly uses the new features of Android L-the latest widgets and some open-source libraries that are recommended and used, such as butterknife and volley. However, more excellent open-source technologies will be used in the future. This article briefly introduces the latest widge knowledge and related open source library technologies used in this project.

1. RecyclerView

RecyclerView is an upgraded version of ListView, because it is very convenient and simple to use. You can refer to Google's official documentation:

RecyclerViewIs a more advanced and flexible versionListView. This widget is a container for large sets of views that can be recycled and scrolled very efficiently. UseRecyclerViewWidget when you have lists with elements that change dynamically.

We can see that RecyclerView is used to display a large amount of data in the same container as ListView. It can be very efficient to reuse and scroll. When the elements on your view often change dynamically and regularly, you can use the RecyclerView control. When we used listview, we were responsible for managing the layout of each item. At the same time, we also had our own item reuse mechanism. When we used more items, we felt quite cumbersome, however, RecycleView will no longer have these problems. RecyclerView is no longer responsible for layout, but focuses only on reuse mechanisms. The layout is managed by LayoutManager. RecyclerView still obtains the object to be displayed through the Adapter, but this Adapter does not inherit BaseAdapter but RecyclerView that comes with RecycleView. adapter, and it is better to specify an inherited from RecyclerView. the model of ViewHolder. The Adapter no longer requires you to return a View, but a ViewHolder. After inheriting from the Adapter, three abstract methods must be implemented:

1>. This method will be called back when RecyclerView requires a ViewHolder. If there is a reusable View, this method will not have to be reversed.

   public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i);

2>. When a View needs to appear on the screen, this method will be called back. You need to change the View based on the data in this method.public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i);
3>. It is used to tell the RecyclerView that multiple views need to display public int getItemCount ();

There is no much difference between the new Adapter and the original Adapter, but we no longer need to write the logic of reuse judgment, because the reuse logic is actually similar and has its own implementation. Like the original AdapternotifyDataSetChangedTo refresh the UI.getItemViewTypeTo obtain the type of the corresponding location, but you no longer need to specify the number of types, because the method can determine the number of types. AddedonViewRecycledThe method allows the user to listen to the time when the View is removed from the screen, and also providesAdapterDataObserverProvided the callback when the data is changed.

ViewHolder is an encapsulation of all individual items. It not only contains the View to be displayed for the item, but also contains other data related to the item, such: the current position, the previous position, the position to be displayed, the number of recycled items, the type of the View, and whether it is in the display medium information. To create a ViewHolder, you need to pass a View object. This View is the display View of the holder. This View usually contains some subviews. We 'd better record these subviews in the holder, it is easy to set different data for reuse.

RecyclerView no longer manages LayoutManager, but uses LayoutManager to manage LayoutManager. We can inherit LayoutManager to implement special LayoutManager. The system provides three common layout managers:

In addition, you can set horizontal and vertical la s for each type. Unfortunately, you cannot add headers. To add headers, we can use different types in the Adapter to achieve this effect.

RecyclerView provides the animation effects of item addition and deletion by default. If we use a Custom Animation, We need to inheritRecyclerView.ItemAnimatorClass.RecyclerView.setItemAnimator()To set our custom animation.

 

2. CardView

CardView inherits from the FrameLayout class. To implement flat UI processing, shadows and rounded corners are usually inseparable. We usually let the artist provide a background image with shadow and rounded corners, now we have a better implementation method, that is, CardView ., Consistent display content in a card layout. A card can contain rounded corners and shadows. CardView is a Layout, so other views can be laid out. The shadow effect is the same as that of the rounded corner. You can set the shadow effect in the xml layout or in the code, you can use the cardElevation attribute or the setCardElevation method to achieve the same effect for the shadow effect. For the rounded corner effect, you can use the cardCornerRadius attribute or the setRadius method to achieve the same effect.

 

3. ToolBar

ToolBar is also a new widget introduced in Android L. It can be regarded as an upgraded version of actionbar because it can replace actionbar. We know that we used actionbar very inflexible in the past because it is a fixed form, but toolbar will change everything. Let's take a look at the official documentation:

  • UseToolbarAs an Action Bar when you want to use the existing Action Bar facilities (such as menu inflation and selection,ActionBarDrawerToggle, And so on) but want to have more control over its appearance.

  • Use a standaloneToolbarWhen you want to use the pattern in your app for situations that an Action Bar wocould not support; for example, showing multiple toolbars on the screen, spanning only part of the width, and so on.

(1) SetToolbarIt is used as an actionbar. This usually happens when you want to use some existing functions of actionbar (for example, you can display the operation items in the menu, respond to the menu Click Event, and useActionBarDrawerToggle), But want to get more control permissions than actionbar.

(2) Use Toolbar as an independent control.Standalone.

If you want to use the first method, the specific representation of the toolbar can be customized through the xml layout. The simplest way to remove the actionbar is to useTheme.AppCompat.NoActionBarTopic. Or set the topic attributes.android:windowNoTitleTrue. Then, it is called in onCreate of ActivitysetSupportActionBar(toolbar)The menu that should have appeared on the ActionBar will automatically appear on the actionbar. Similarly, if you use the second method, you do not need to remove the actionbar (the two can coexist) by using the Toolbar as an independent control, and you can use any theme. However, in this case, the menu is not automatically displayed on the Toolbar, And the Toolbar does not respond to the callback function of the menu. If you want to display the menu item on the Toolbar, you must manually enter the inflate menu.

 

4. Palette

Palette is a color filter that can extract highlight colors from the image. In this way, the color value can be assigned to the toolbar or other views to unify the entire tone of the interface.

The Palette class extracts the following highlighted colors:

Vibrant (dynamic)

Vibrant dark (Vibrant dark color)

Vibrant light (Vibrant and bright)

Muted (soft)

Muted dark (soft and dark)

Muted light (soft and bright)

For specific implementation, see the Aiguille project.

 

5. butterknife

ButterKnife is a View injection framework dedicated to the Android system. It frees you from these annoying and bloated code. The specific implementation details are not listed here. You can directly look at the project source code and you will understand it at a glance. (Do not forget to configure it during use. There should be a lot of online configuration processes. If there are still problems, you can leave a message ).

 

6. volley

Volley is Google's Android Asynchronous Network request framework and image loading framework. Released at Google I/O 2013. Volley's characteristics can be seen from the numerous rapid rockets in the name and matching diagram: It is especially suitable for network operations with small data volumes and frequent communication. (I personally think that the vast majority of network operations in Android applications belong to this type ).

Volley's main features

(1). Strong scalability. Volley is mostly based on interface design and is highly configurable.
(2). To a certain extent, it complies with Http specifications, including response code (2xx, 3xx, 4xx, 5xx), Request Header Processing, and Cache Mechanism support. Retry and priority definition are also supported.
(3) by default, Android2.3 and above are implemented based on HttpURLConnection, and HttpClient is implemented for less than 2.3.
(4) provides a simple image loading tool.

 

The above is a general introduction. The Aiguille project provides detailed usage details of various widgets and open-source libraries. Welcome to fork.

Project address: https://github.com/wwkai555/Aiguille

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.