类似QQ在线离线好友界面

Posted 沁宇

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类似QQ在线离线好友界面相关的知识,希望对你有一定的参考价值。

把头像设置成圆形的代码如下:

  1 package com.example.lesson6_11_id19;
  2 
  3 import android.content.Context;
  4 import android.content.res.TypedArray;
  5 import android.graphics.Bitmap;
  6 import android.graphics.Canvas;
  7 import android.graphics.Color;
  8 import android.graphics.Paint;
  9 import android.graphics.PorterDuff;
 10 import android.graphics.PorterDuffXfermode;
 11 import android.graphics.RectF;
 12 import android.graphics.Xfermode;
 13 import android.graphics.drawable.Drawable;
 14 import android.graphics.drawable.NinePatchDrawable;
 15 import android.util.AttributeSet;
 16 import android.widget.ImageView;
 17 
 18 public class CircleImageView extends ImageView {
 19     private static final Xfermode MASK_XFERMODE;
 20     private Bitmap mask;
 21     private Paint paint; 
 22     private int mBorderWidth = 10;
 23     private int mBorderColor = Color.parseColor("#f2f2f2");
 24     private boolean useDefaultStyle = false;
 25     
 26     static {
 27         PorterDuff.Mode localMode = PorterDuff.Mode.DST_IN;
 28         MASK_XFERMODE = new PorterDuffXfermode(localMode);
 29     }
 30     
 31     public CircleImageView(Context context) {
 32         super(context);
 33     }
 34 
 35     public CircleImageView(Context context, AttributeSet attrs) {
 36         this(context, attrs, 0);
 37     }
 38     
 39     public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
 40         super(context, attrs, defStyle);
 41         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularImage);
 42         mBorderColor = a.getColor(R.styleable.CircularImage_border_color, mBorderColor);
 43         final int def = (int) (2*context.getResources().getDisplayMetrics().density + 0.5f);
 44         mBorderWidth = a.getDimensionPixelOffset(R.styleable.CircularImage_border_width, def);
 45         a.recycle();        
 46     }
 47 
 48     private void useDefaultStyle(boolean useDefaultStyle) {
 49         this.useDefaultStyle = useDefaultStyle;
 50     }
 51     
 52     @Override
 53     protected void onDraw(Canvas canvas) {
 54         if(useDefaultStyle) {
 55             super.onDraw(canvas);
 56             return ;
 57         }
 58         final Drawable localDraw = getDrawable();
 59         if(localDraw == null) {
 60             return ;
 61         }
 62         if(localDraw instanceof NinePatchDrawable) {
 63             return ;
 64         }
 65         if (this.paint == null) {  
 66             final Paint localPaint = new Paint();  
 67             localPaint.setFilterBitmap(false);  
 68             localPaint.setAntiAlias(true);  
 69             localPaint.setXfermode(MASK_XFERMODE);  
 70             this.paint = localPaint;  
 71         }  
 72         final int width = getWidth();  
 73         final int height = getHeight();  
 74         /** ����layer */  
 75         int layer = canvas.saveLayer(0.0F, 0.0F, width, height, null, 31);  
 76         /** ����drawable�Ĵ�С */  
 77         localDraw.setBounds(0, 0, width, height);  
 78         /** ��drawable�

以上是关于类似QQ在线离线好友界面的主要内容,如果未能解决你的问题,请参考以下文章

如何重新排列qq好友

QQ群友在线/离线,如何测试?

怎么把qq好友按添加时间排序

QQ好友列表是怎么排序的

XMPPFramework - 如何获取在线和离线好友列表?

JAVA入门到精通-第93讲-山寨QQ项目7-好友在线提示