Android仿微信群聊头像

2019-12-10 19:12:39王旭
这篇文章主要为大家介绍了Android仿微信群聊头像的相关资料,感兴趣的小伙伴们可以参考一下  

工作中需要实现仿钉钉群头像的一个功能,就是个人的头像拼到一起显示,看了一下市场上的APP好像微信的群聊头像是组合的,QQ的头像不是,别的好像也没有了。

给大家分享一下怎么实现的吧。首先我们先看一下效果图:

Android仿微信群聊头像

好了,下面说一下具体怎么实现的:

实现思路

  • 1.首先获取Bitmap图片(本地、网络)
  • 2.创建一个指定大小的缩略图
  • 3.组合Bitmap图片

    很简单,本地图片需要我们从本地读取,如果是网络图片我们也可以根据URL来获取bitmap进行组合

    具体实现过程

    1.布局文件:

    <LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
      xmlns:tools="http://www.easck.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:gravity="center"
      android:orientation="vertical"
      android:background="#987"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
      <TextView
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
      <ImageView
        android:src="@drawable/j"
        android:id="@+id/iv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
      <TextView
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
      <ImageView
        android:src="@drawable/j"
        android:id="@+id/iv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
      <TextView
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
      <ImageView
        android:src="@drawable/j"
        android:id="@+id/iv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
      <TextView
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
      <ImageView
        android:src="@drawable/j"
        android:id="@+id/iv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
      <TextView
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
    
    </LinearLayout>