先上效果图:
实现步骤:
1. 下载 android-circular-avatar.jar ;
2. 在布局文件中引用
cn.kongnannan.circularavatar.CircularImageView 控件
3. 在Activity中,获得实例,把 ArrayList<Bitmap> 设置给 CircularImageView
注: ArrayList<Bitmap> size() 最大为5
example:
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<cn.kongnannan.circularavatar.CircularImageView
android:id="@+id/circularImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp" />
</LinearLayout>
MainActivity:
public class MainActivity extends Activity{
private CircularImageView circularImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.qunavatar_activity);
initView();
}
private void initView(){
circularImageView = (CircularImageView) findViewById(R.id.circularImageView);
Drawable d1 = getResources().getDrawable(R.drawable.bg1);
Drawable d2 = getResources().getDrawable(R.drawable.bg2);
Drawable d3 = getResources().getDrawable(R.drawable.bg3);
Drawable d4 = getResources().getDrawable(R.drawable.bg4);
Drawable d5 = getResources().getDrawable(R.drawable.bg5);
BitmapDrawable bd1 = (BitmapDrawable) d1;
Bitmap b1 = bd1.getBitmap();
BitmapDrawable bd2 = (BitmapDrawable) d2;
Bitmap b2 = bd2.getBitmap();
BitmapDrawable bd3 = (BitmapDrawable) d3;
Bitmap b3 = bd3.getBitmap();
BitmapDrawable bd4 = (BitmapDrawable) d4;
Bitmap b4 = bd4.getBitmap();
BitmapDrawable bd5 = (BitmapDrawable) d5;
Bitmap b5 = bd5.getBitmap();
ArrayList<Bitmap> list = new ArrayList<Bitmap>();
list.add(b1);
list.add(b2);
list.add(b3);
list.add(b4);
list.add(b5);
circularImageView.setImageBitmaps(list);
}
}
OK,搞定了!