Android imitation wechat contact alphabetic sorting effect

This example shares the specific code of Android contact alphabetical sorting for your reference. The specific contents are as follows

Implementation idea: first, let's talk about the layout. The whole layout is a relative layout. At the bottom is a listview. Above the listview is a user-defined view (letters displayed on the right), and at the top is a textview (box in the middle of the screen).

First, let's talk about the custom view on the right. The letters are drawn on the view. First, calculate the height of the view, and then divide it by the length of the letter array to get the height of each character; The width of each letter is the same, so 30sp is set directly here;

Listview shows the names of 108 Liangshan heroes;

The project uses a pinyin4j.jar to convert each name into pinyin, and then uses charat (0) to obtain the first letter of Pinyin;

Each item of the listview is a linear layout wrapped by two textviews. The TV above shows the first letter of Pinyin, and the TV below shows the name; Judge whether the Pinyin initials of the current item and the previous item are the same in the adapter. If they are the same, hide the TV on the current item;

Then set a custom listener in the custom view; When clicking the custom view, judge which letter is currently clicked according to the height, and then set the position where listview will jump according to the letter;

First look at the layout:

Don't worry about looking at the mainactivity code. First look at the code of the custom view:

Now I have prepared a picture for you to calculate the XY coordinates of letters:

Finally, the code of mainactivity:

Source code download: http://xiazai.jb51.net/201611/yuanma/AndroidWXcontact (jb51.net).rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>