Android Contact Full effects Implementation (upper), grouped navigation and extrusion animation

Source: Internet
Author: User
Tags sort

Remember that when I first contacted Android, I was interested in the special effects of the system contacts, which grouped according to the initials of the contact's last name on the phone and always displayed a current group at the top of the interface. As shown in the following illustration:

What interests me most is that when the latter group is colliding with the previous group, a top extrusion animation is produced. At that time I thought of various ways to achieve this special effect, but not to the home, can not succeed. Now more than two years later, I have grown a lot, and then go back to think about this function, suddenly found that there is a train of thought, so immediately recorded down to share with you.

First of all, we need to know the knowledge points in advance, here we need to use the most is sectionindexer, it can effectively help us to control the group. Since Sectionindexer is an interface, you can customize a subclass to implement Sectionindexer, but it's too troublesome to write a sectionindexer implementation yourself. Here we use Android directly to provide a good implementation alphabetindexer, it is enough to implement the contact grouping function.

The Alphabetindexer constructor needs to pass in three arguments, the first argument is cursor, the second is the Sortedcolumnindex integer, and the third argument is the alphabet string. Where cursor is to pass the cursor that we have detected from the database, Sortedcolumnindex is to indicate which column we are using to sort, and alphabet specifies the alphabet collation, for example: " ABCDEFGHIJKLMNOPQRSTUVWXYZ ". With Alphabetindexer, we can use its getpositionforsection and Getsectionforposition methods to find the group where the current position is, and where the current group is located, In order to achieve similar to the system Contact Group navigation and extrusion animation effect, about Alphabetindexer more detailed details, please refer to the official documentation.

So how are we going to sort the contacts? As mentioned before, there is a sortedcolumnindex parameter, where is this sortedcolumn? Let's take a look at the system contact raw_contacts this table (/DATA/DATA/COM.ANDROID.PROVIDERS.CONTACTS/DATABASES/CONTACTS2.DB), which has a complex structure with More than 20 columns, including one named Sort_key, that's what we're looking for! As shown in the following illustration:

As you can see, this column is very humane to help us record the pinyin corresponding to the Chinese character, so that we can easily sort the contact by the value of this column.

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.