QQ / wechat friend list using listview in Android

First attach the operation results:

If you haven't learned listview, please take a look at the basic knowledge first. I don't want to say so much.

The first is the listview layout

Why do I set this here

Listview is the most commonly used control in Android. During UI design, many people want to change its background so that it can conform to the overall UI design. Changing the background is very simple. Just prepare a picture and specify the attribute Android: background = "@ drawable / BG", but don't be happy too early. After you do this, you find that the background has changed, However, when you drag or click the blank position of the list, you find that the listitems turn black, which destroys the overall effect.

What caused this? At first, I thought it was because I set the background to white, and then there was a color difference. Later, I checked the data and found that this should start with the effect of listview. The default listitem background is transparent, while the listview background is fixed, Therefore, in the process of scrolling the scroll bar, if the current display content of each item is mixed with the background in real time, the Android system uses an attribute called Android: cachecolorhint to optimize the process. Under the black theme, the default color value is #191919, so the previous picture appears, half of which is black, Then what shall I do?

If you just change the color of the background, you can directly specify Android: cachecolorhint as the color you want. If you use an image as the background, you can just specify Android: cachecolorhint as transparent (#00000000). Of course, some efficiency will be sacrificed for beautification.

Because the list of friends we use is complex, one ImageView and two textviews. So we need to customize the adapter. The textview below is a textview I created myself to achieve the scrolling effect of nickname and personalized signature. Because it takes up too many resources, it is not recommended to scroll everyone's nicknames and personal signatures. Just get the focus scroll. I won't change it. I'll leave it to you

MyTextView.class

Customize the layout file referenced by the adapter

Custom adapter code

Myadapter.class

I created a personal information object, including avatar, nickname and personal signature, for the convenience of adding to the list

Then there is mainactivity.class. I saved everyone's Avatar information, nickname and personal signature in the array.

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of 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
分享
二维码
< <上一篇
下一篇>>